domthom21 / eurocodedesign

Typed python framework for eurocode calculations
https://eurocodedesign.readthedocs.io/
Mozilla Public License 2.0
5 stars 1 forks source link

[BUG] No overloaded return types on unit multiplication and division #42

Closed domthom21 closed 1 year ago

domthom21 commented 1 year ago

Describe the bug Currently, multiplication and division of Units return an AbstractUnit or float. However, they should return the specific unit type

To Reproduce

 _elastic_modulus: Pascal = 210_000*N()/mm2()
$ python -m mypy --config-file mypy.ini -p eurocodedesign
eurocodedesign\materials\structuralsteel.py:41: error: Incompatible types in
assignment (expression has type "AbstractUnit | float", variable has type
"Pascal")  [assignment]
        _elastic_modulus: Pascal = 210_000*N()/mm2()

Expected behavior E.g. 210_000*N()/mm2() should return Pascal specifically

Additional context Fix according to https://docs.python.org/3/library/typing.html#typing.overload Overloading is necessary for __mul__ and __true_div__ in units\__init__.py according to _allowed_multipliucations

domthom21 commented 1 year ago

Fixed with #74