-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(entities): improve docs, doctests, and typing #1034
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @maukoquiroga :)
Thanks @maukoquiroga. This is marked as depending on #1033 but I see redundant changes, for example in the config file. I would be in favour of having a single PR as they seem to address the same issue (openfisca/openfisca-doc#244) and to improve documentation altogether. |
Corrected it
I will rebase properly, that should get us rid of the conflicts 😃
I thought so initially as well, and I tried, then I decided to split this work by "submodule" and add doc as well as fixing the doctests. Here's what happened:
I think we probably won't be able to fix all the doctests soon, that's why I changed from an horizontal to a vertical (submodules) approach. Happy to have an extended discussion on that with the community if you think that could be useful! |
36a5929
to
799ada9
Compare
56bd358
to
3e159b4
Compare
c48b382
to
0d00a4a
Compare
183fca2
to
1fbfa33
Compare
0e70e61
to
3c56ee5
Compare
1fbfa33
to
6c88052
Compare
3c56ee5
to
8fe2a41
Compare
9bc6af7
to
d773990
Compare
350d76b
to
51a2173
Compare
9892461
to
d8c1a62
Compare
acb127e
to
f146d2d
Compare
6a5cf6f
to
6169d44
Compare
f146d2d
to
1c4e1c7
Compare
17d128c
to
845235d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @maukoquiroga! Great contribution 👏
I ran all the tests and they passed :)
I don't think I know enough to approve the structural changes though 😅
Co-authored-by: Hajar AIT EL KADI <48837850+HAEKADI@users.noreply.github.com>
I am in favor of more typing, more doctest but I am ,ot sure I can grasp all the implications of the changes ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added documentation is great!
However, I don't understand the consequences of introducing an abstract base class system and this “variable proxy” system, so I cannot approve that PR 😕
Co-authored-by: Matti Schneider <matti.schneider@beta.gouv.fr>
Thanks @MattiSG ! Concerning the abstract class system, it is not one. As I've described it:
Structural sub-typing is described in PEP 544. Quoting it:
In other words, there are no consequences beyond type-checks —no runtime impact then. To make the point, an This has, however, one major benefit: we remove circular module dependencies from the codebase, which has an actual positive impact in terms of modularity and testability.
That is just an abstraction, or in DDD, a port. As I see it has two impacts:
Beyond the "design" aspect of it, the actual recipe, the descriptor, is just standard Python —a huge deal of the function system, properties, and so on, are just syntactic sugar; behind-the-scenes they're just descriptors. Finally, as you can see from the changeset, the introduced syntax is more coherent with the |
Superseded by #1255 |
Part of #1061
Superseded by #1220
Superseded by #1252
Superseded by #1255
Documentation
Doctests
Typing
typing
, under three categories:types
: for data-types, which are subsequently split into two sub-categories:XType
: an actual data-type —for example an arrayXLike
: an object where the actual data-type is irrelevant, but that can be coerced toX
.protocols
: for behaviours —think interfaces but for the sole purpose of static type-checkingschemas
: type-safe data-objects —mostly for dictionariesDeprecations
Entity.set_tax_benefit_system
: now provided by a standardproperty
setter.Entity.check_role_validity
: moved to helpers as it had nothing to do with entitiesNew features
entity 1 - * variable
declarative, thanks to the_VariableProxy
descriptordataclass
andslots
for reduced boilerplate and improved performanceTechnical changes
GroupEntity
, replaces dynamicrole
attributes assignment for an explicit caching mechanismslots
and thus the performance gainsNotes
Entity
andPopulation
,Simulation
andSimulationBuilder
, and so on. Although the changset is backward-compatible, future contributions enforcing this choice may introduce breaking changes.adapter
,proxy
,port
, orrepo
: beyond the pure relationship between models, the behavioural logic between them is extracted to specialised models —in this case,querying
variables is extracted fromEntity
to a_VariableProxy
. This is just a subset of 1.protocols
, orduck-typing
, orstructural sub-typing
: that means type-checks are done not against the actual implementation of a model, but against aprotocol
, that is, the equivalent of aninterface
, or anabstract model
, but without impact at runtime.schemas
. But, contrary to regularschemas
used to validate, serialise, and deserialise data from/to models, these schemas are purely type-safe data objects, meant for type-checks, without impact at runtime.Extended note on data-schemas
What if, instead of just using
schemas
as typed-dicts for type-checks, we used them at runtime to compulsorily:a. check types at runtime?
b. validate data at runtime?
c. serialise/deserialise data —as suggested in #1071 ?
d. enforce contracts, or domain logic —both in terms of data ("has to be >0") and representation ("tojson()")?
For
Formula
andTest
.OpenAPI
Against
Performance: whereas declarative data transmutation can even increase performance for individual situations —WebAPI—, a naive or out-of-the-box implementation (or anything with a complexity of at least
O(n)
) will certainly have a very penalising impact on performance for large population simulations.This due to several reasons:
numpy
already provides data type-casting, with configurable levels of safety, and C-optimisedPossible workarounds:
--safe
or--strict