1+ from __future__ import annotations
2+
3+ from typing import Any , Dict , Optional , Sequence
4+
15import copy
26import glob
37import importlib
@@ -27,28 +31,27 @@ class TaxBenefitSystem:
2731
2832 It stores parameters (values defined for everyone) and variables (values defined for some given entity e.g. a person).
2933
30- :param entities: Entities used by the tax benefit system.
31- :param string parameters: Directory containing the YAML parameter files.
32-
34+ Attributes:
35+ parameters: Directory containing the YAML parameter files.
3336
34- .. attribute:: parameters
37+ Args:
38+ entities: Entities used by the tax benefit system.
3539
36- :obj:`.ParameterNode` containing the legislation parameters
3740 """
3841 _base_tax_benefit_system = None
39- _parameters_at_instant_cache = None
42+ _parameters_at_instant_cache : Optional [ Dict [ Any , Any ]] = None
4043 person_key_plural = None
4144 preprocess_parameters = None
4245 baseline = None # Baseline tax-benefit system. Used only by reforms. Note: Reforms can be chained.
4346 cache_blacklist = None
4447 decomposition_file_path = None
4548
46- def __init__ (self , entities ) :
49+ def __init__ (self , entities : Sequence [ Entity ]) -> None :
4750 # TODO: Currently: Don't use a weakref, because they are cleared by Paste (at least) at each call.
48- self .parameters = None
51+ self .parameters : Optional [ ParameterNode ] = None
4952 self ._parameters_at_instant_cache = {} # weakref.WeakValueDictionary()
50- self .variables = {}
51- self .open_api_config = {}
53+ self .variables : Dict [ Any , Any ] = {}
54+ self .open_api_config : Dict [ Any , Any ] = {}
5255 # Tax benefit systems are mutable, so entities (which need to know about our variables) can't be shared among them
5356 if entities is None or len (entities ) == 0 :
5457 raise Exception ("A tax and benefit sytem must have at least an entity." )
@@ -139,13 +142,15 @@ def load_variable(self, variable_class, update = False):
139142
140143 return variable
141144
142- def add_variable (self , variable ):
143- """
144- Adds an OpenFisca variable to the tax and benefit system.
145+ def add_variable (self , variable : Variable ) -> Variable :
146+ """Adds an OpenFisca variable to the tax and benefit system.
147+
148+ Args:
149+ variable: The variable to add. Must be a subclass of Variable.
145150
146- :param .Variable variable: The variable to add. Must be a subclass of Variable.
151+ Raises:
152+ openfisca_core.errors.VariableNameConflictError: if a variable with the same name have previously been added to the tax and benefit system.
147153
148- :raises: :exc:`.VariableNameConflictError` if a variable with the same name have previously been added to the tax and benefit system.
149154 """
150155 return self .load_variable (variable , update = False )
151156
@@ -231,7 +236,7 @@ def load_extension(self, extension):
231236 """
232237 Loads an extension to the tax and benefit system.
233238
234- :param string extension: The extension to load. Can be an absolute path pointing to an extension directory, or the name of an OpenFisca extension installed as a pip package.
239+ :param str extension: The extension to load. Can be an absolute path pointing to an extension directory, or the name of an OpenFisca extension installed as a pip package.
235240
236241 """
237242 # Load extension from installed pip package
@@ -251,19 +256,20 @@ def load_extension(self, extension):
251256 extension_parameters = ParameterNode (directory_path = param_dir )
252257 self .parameters .merge (extension_parameters )
253258
254- def apply_reform (self , reform_path ):
255- """
256- Generates a new tax and benefit system applying a reform to the tax and benefit system.
259+ def apply_reform (self , reform_path : str ) -> "TaxBenefitSystem" :
260+ """Generates a new tax and benefit system applying a reform to the tax and benefit system.
257261
258262 The current tax and benefit system is **not** mutated.
259263
260- :param string reform_path: The reform to apply. Must respect the format *installed_package.sub_module.reform*
264+ Args:
265+ reform_path: The reform to apply. Must respect the format *installed_package.sub_module.reform*
261266
262- :returns: A reformed tax and benefit system.
267+ Returns:
268+ TaxBenefitSystem: A reformed tax and benefit system.
263269
264270 Example:
265271
266- >>> self.apply_reform('openfisca_france.reforms.inversion_revenus')
272+ >>> self.apply_reform('openfisca_france.reforms.inversion_revenus')
267273
268274 """
269275 from openfisca_core .reforms import Reform
@@ -412,9 +418,9 @@ def get_variables(self, entity = None):
412418 """
413419 Gets all variables contained in a tax and benefit system.
414420
415- :param . Entity entity: If set, returns only the variable defined for the given entity.
421+ :param Entity entity: If set, returns only the variable defined for the given entity.
416422
417- :returns: A dictionnary , indexed by variable names.
423+ :returns: A dictionary , indexed by variable names.
418424 :rtype: dict
419425
420426 """
0 commit comments