PSLmodels / Tax-Brain

Tax-Brain is an integrator model for PSL tax models
http://taxbrain.pslmodels.org/
MIT License
8 stars 12 forks source link

typing.py #162

Closed jdebacker closed 3 years ago

jdebacker commented 3 years ago

@andersonfrailey I can't quite figure out what the purpose of the typing.py module is. Can you help me understand?

hdoupe commented 3 years ago

@jdebacker this just defines a few types to help document function signatures.

For example, the TaxcalcReform and ParamToolsAdjustment are used here:

https://github.com/PSLmodels/Tax-Brain/blob/05984901c87645b630d348a328f3da5588b5ade7/taxbrain/utils.py#L257-L285

Side note: is_paramtools_format is now implemented in Tax-Calculator: https://taxcalc.pslmodels.org/api/parameters.html#taxcalc.parameters.is_paramtools_format

jdebacker commented 3 years ago

@hdoupe Thanks for the reply. I haven't used type hinting or see it before. Just read this Real Python article and not clear on benefits if you already have docstrings noting the types for the inputs and output of functions. Can help catch additional errors?

chusloj commented 3 years ago

@jdebacker These type hints from the typing module are mostly used for type-checking during development in IDEs. However, if you use a static type-checker like mypy you can find errors based on type hints. Also, I think you can use the typing module with the built-in isinstance() function to check for type errors at runtime.

@hdoupe Does this sound correct?

MaxGhenis commented 3 years ago

IDEs can also automatically populate the docstring types based on type hints.

jdebacker commented 3 years ago

Got it - thanks for all the input on the use of the typing package and how type hints can be useful.