Open Christian-B opened 1 week ago
tests only need typing enough to pass
mypy is smart enough to know list[str] and list[str] are the same
so mixing then especially why developing this chain of prs is not a problem.
Speed testing between the various way to handle use of Optional values a: Optional[int] = 1 b = 0
Over 10,000,000 iterations
b+= a
0.72 but will fail mypy
assert a is not None
b+= a
0.86
b+= cast(int, a)
1.34
assert isinstance(a, int)
b+= a
1.50
Therefor where mypy can not distinguish between None or an Object pick assert None but where mypy can not distinguish between type A or B use cast,
Remember of course incorrect cast will not save you at runtime! Assert will unless turned off
See: https://peps.python.org/pep-0585/
Starting with python 3.9 where applicable Standard classes
So instead of doing List[int] we can type as list[int]
As readthedocs is able to use type hint in the def to document param types we will remove ALL tying from the method documentation.
While doing this I will apply the rule at all (OK almost all) methods must be typed.
Exception will be (I reserve the right to add to this list)
Deep generic methods like AbstractBase.new
spinn_utilities/citation as I am not civinced we want to keep this code
All public methods must be documented
A protected (single underscore) should be documented.
Private need not be documented.
WILL not work with Python 3.8!
Features only available in Python 3.10 will not be used so we will keep