Skip to content

Add typings#976

Draft
cesco-fran wants to merge 7 commits intoopenfisca:masterfrom
cesco-fran:add-typings
Draft

Add typings#976
cesco-fran wants to merge 7 commits intoopenfisca:masterfrom
cesco-fran:add-typings

Conversation

@cesco-fran
Copy link

Technical changes

  • Add typings to the source code.

@bonjourmauko
Copy link
Member

I love this ❤ it adds some lecture overhead at first but having explicit contracts will definitely ease refactoring, bug correction, debugging... I would at a minimum create types mapping each important class. It's a layer of indirection maybe but I think it would make types more "drop-in" and ease code comprehension for most newcomers.

Copy link
Author

@cesco-fran cesco-fran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since is possible to use the class as type ...there will be no indirection for type that correspond to class.

@bonjourmauko bonjourmauko self-assigned this Apr 1, 2021
@bonjourmauko bonjourmauko added the kind:refactor Refactoring and code cleanup label Apr 1, 2021
@bonjourmauko bonjourmauko changed the title Add Typings [WIP] Add Typings Apr 1, 2021
@bonjourmauko
Copy link
Member

I think we should move forward with this, any help needed?



#TODO change with a more specific type
ArrayLike = Any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be shipped out of the box in Numpy 1.20/21

self.variable = variable
self.simulation = population.simulation
self._memory_storage = InMemoryStorage(is_eternal = (self.variable.definition_period == ETERNITY))
def __init__(self, variable:'Variable', population:'Population'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flake won't like the lack of spaces.

Also you can forward-reference them no?

def __init__(self, variable:'Variable', population:'Population'):
self.population:'Population' = population
self.variable:'Variable' = variable
# TODO change once decided if simulation is needed or not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this requires a bit more of examination. I'll take a look.

self.variable:'Variable' = variable
# TODO change once decided if simulation is needed or not
if population.simulation is None:
raise Exception('You need a simulation attached to the population')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error messages in OpenFisca are meant to help the users discover not just what is wrong, but how can they solve their problems or reach for help. Could you develop this further?

@bonjourmauko bonjourmauko added the kind:roadmap A group of issues, constituting a delivery roadmap label Sep 29, 2021
@bonjourmauko bonjourmauko changed the title [WIP] Add Typings Add Typings Oct 25, 2024
@bonjourmauko bonjourmauko changed the title Add Typings Add typings Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:refactor Refactoring and code cleanup kind:roadmap A group of issues, constituting a delivery roadmap

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants