Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added more type hints #111

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

vasdee
Copy link

@vasdee vasdee commented Apr 24, 2022

I'm interested in contributing to this project, I was very glad to see that hbmqtt was getting some much needed love :)

I used this opportunity to get familiar with the internals of the code base, but at the same time I found it useful to add more and more type hints as I was exploring. I'm sure there will be some mistakes here and there, some of them were definitely "best guesses".

Just within these added hints alone, it has already high lighted some areas that could already be tightened up, so I think it is definitely worth the effort for adding as much hinting as possible

@FlorianLudwig
Copy link
Member

@vasdee thanks! This is awesome.

Looking through it might take some time. Can you have a look at the a filing CI pipeline?

amqtt/mqtt/protocol/handler.py Outdated Show resolved Hide resolved
amqtt/mqtt/connect.py Outdated Show resolved Hide resolved
amqtt/mqtt/connack.py Show resolved Hide resolved
amqtt/mqtt/connack.py Outdated Show resolved Hide resolved
amqtt/broker.py Outdated Show resolved Hide resolved
amqtt/version.py Outdated Show resolved Hide resolved
@FlorianLudwig
Copy link
Member

Please run mypy amqtt and have a look. Please note that the master branch has 111 errors from mypy and adding more types, makes mypy check more of the code - so the number of errors increased.

You don't have to get the errors down to zero to get this MR into a merge-able territory - just check the mypy output for potential wrong annotations.

@vasdee
Copy link
Author

vasdee commented Apr 30, 2022

This is about all the type hinting that I can add, and I can't fix all the mypy errors until work is done to remove the excessive use of None
Most of the errors now are because nearly every attribute is an Optional so naturally, accessing an attribute of a None type raises an issue with mypy.

I think this is a good thing, it highlights that cleanup work can be done to make it cleaner :)

@vasdee vasdee force-pushed the feature/adding-type-hints branch 2 times, most recently from d8b1144 to 7d805bf Compare April 30, 2022 09:39
* added __future__ annotations for < 3.10 compatibility
* added as much type hints as possible
* added more type hinting for __slots__
* added typed dict for Subscription and Unsubscription possibly only a
python3.8 feature
@vasdee vasdee force-pushed the feature/adding-type-hints branch from fb07daf to 568b1a7 Compare May 14, 2022 01:45
@vasdee
Copy link
Author

vasdee commented May 14, 2022

Any progress on getting this merged? I feel it is at a pretty good state and has given me some clean up ideas to further reduce the mypy errors.

@vasdee
Copy link
Author

vasdee commented May 14, 2022

looks like there is some failing tests, which I haven't figured out why they would be failing with type hint additions. This doesn't happen on Master so i'm not sure what is going on..

FAILED tests/test_broker.py::test_client_publish_acl_permitted - asyncio.exceptions.TimeoutError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants