WIP: Use monkeytype to apply typehints#44
Draft
hmaerki wants to merge 3 commits intoganehag:masterfrom
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.pyrunning 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
Anytype 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).