-
Notifications
You must be signed in to change notification settings - Fork 2
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
Typing and export PresenceError #3
Conversation
Previously type checkers like mypy would give an error when typechecking code using the library: Skipping analyzing "discordrp": module is installed, but missing library stubs or py.typed marker This patch fixes this issue.
According to https://peps.python.org/pep-0484/#version-and-platform-checking type checkers should understand simple platform checks, however `self._platform == WINDOWS` is not simple enough for mypy 1.3.0. Replaced it with `sys.platform == 'win32'` so the type-checker doesn't get mad at `socket.AF_UNIX` on windows.
This doesn't help the type-checking, but makes all the platform checks done in the same way in an attempt to be less confusing.
For the |
Thanks for all the help. Right now I am occupied with work but I'll take a look at it when I get the chance. |
When no exception is raised these variables are None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay! At this point, I think it would be better if separate socket classes were made for both platforms to avoid leaving the socket
typed as Any
. I kept your commits but also added my own refactoring. From my end on MacOS, it's still mypy --strict
compliant, but let me know if it doesn't work for you or if you have any suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer Optional[T]
over Union[T, None]
Separate socket classes might be the cleanest option. We're still left with errors from Adding a Also, when adding the action to test the typing on windows I realized that I broke python 3.9 compatibility with the new union syntax, so I changed it to the old one in 0a5623c (now 48f192f). :^) |
Fair, I'll just change the commit and force push |
The library supports python 3.9, which does not support union with |
This fixes typechecking on windows, as socket.AF_UNIX is not defined there. Adding unused-ignore also fixes the unused ignore error on mac and linux.
Thanks! I'll use |
Just upstreaming some more of the changes I've made in my copy of your library (Amund211/prism@358bd76), though a bit less invasive this time. Feel free to pick and choose which commits you want or don't want.
Summary of the changes:
Presence
is exported from__init__.py
(mypy
was complaining about this)presence.py
to make it passmypy --strict
(there are still someAny
types and 1 call tocast
py.typed
marker. This makes the type hints visible to people using the library, as before you would get an error that the module was installed, but could not be type-checkedPresenceError
as an export from__init__.py