WIP: Use monkeytype to apply typehints #44
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adding typehints
I saw this issue #30 and tried to add type hints.
This is how far I got - now it is time to get feedback.
What I did:
This way I collected runtime data from the test folder and from
example_mbus.py
running agains real meters.Then I applied the typehints
monkeytype apply meterbus.zzz
.The result is here WIP: Applies types hints using monkeytype.
The easy typehints
About 60% of the typehints are simple and make sense.
The complex typehints
Then I continued manually starting to resolve the
Any
type hints.For example:
def _parse_vifx(self) -> Any:
which I manually resolved to:
def _parse_vifx(self) -> Tuple[Union[None, int, float], Union[None, str, MeasureUnit], Union[None, str, VIFUnit, VIFUnitExt, VIFUnitSecExt], Union[None, VIFUnitEnhExt]]:
Another complex structure is:
Before:
and with the typehints resolved:
These changes are here: hmaerki@d6984ab
How to continue?
If typehints are really wanted, I see several work packages:
core_objects
. There are many enumerations and there datatypes spread in the whole package. There might be ways to hide all the different datatypes.def _parse_vifx()
returns a tuple of four values (Tuple[Union[None, int, float], Union[None, str, MeasureUnit], Union[None, str, VIFUnit, VIFUnitExt, VIFUnitSecExt], Union[None, VIFUnitEnhExt]]:
). There might be a cleaner way to do that.My proposal would be to go for A) and B).