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

Broken typing annotations fixed #949

Merged
merged 3 commits into from
Sep 11, 2023

Conversation

jolaf
Copy link
Contributor

@jolaf jolaf commented Sep 9, 2023

Running an app using websocket-client under typeguard produced a number of crashes due to typing annotations in websocket-client being broken and not compliant to the real data types. This PR fixes those broken annotations.

Fixes #934 and #948.

@codecov
Copy link

codecov bot commented Sep 9, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.08% 🎉

Comparison is base (a3f4c3a) 83.33% compared to head (cdb4827) 83.41%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #949      +/-   ##
==========================================
+ Coverage   83.33%   83.41%   +0.08%     
==========================================
  Files          13       13              
  Lines        1374     1381       +7     
  Branches      258      258              
==========================================
+ Hits         1145     1152       +7     
  Misses        152      152              
  Partials       77       77              
Files Changed Coverage Δ
websocket/_abnf.py 89.86% <100.00%> (+0.04%) ⬆️
websocket/_app.py 79.85% <100.00%> (ø)
websocket/_cookiejar.py 97.14% <100.00%> (+0.08%) ⬆️
websocket/_core.py 81.51% <100.00%> (+0.08%) ⬆️
websocket/_socket.py 55.96% <100.00%> (+0.40%) ⬆️
websocket/_url.py 100.00% <100.00%> (ø)
websocket/_utils.py 81.57% <100.00%> (+1.02%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@engn33r
Copy link
Collaborator

engn33r commented Sep 9, 2023

Using | instead of or is not supported in Python 3.8 or 3.9 because PEP 604 was introduced in Python 3.10. This is the same reason PR #945 was not included. This is why the CI tests are failing.

Currently a single release of websocket-client is intended to support all Python versions that are not EOL. If you'd suggest a change in strategy to support multiple versions simultaneously, I'm open to ideas.

@jolaf
Copy link
Contributor Author

jolaf commented Sep 9, 2023

If you want typing annotations valid for Python 3.8, you should write Union[str, int] instead, which is much more cumbersome.

Your old str or int syntax, though formally valid in Python 3.8, is totally broken is essence.

@engn33r
Copy link
Collaborator

engn33r commented Sep 10, 2023

I looked into this more, you're right. Even mypy outputs an error of "Invalid type comment or annotation" on the lines using or.

In order to maintain backwards compatibility with 3.8, would you be willing to replace the usage of | with Union[] or a similar change to allow the existing CI to pass? I can work on editting the changes in this PR if you prefer.

@jolaf
Copy link
Contributor Author

jolaf commented Sep 10, 2023

I've fixed the annotations, please run the checks.

Or even better make checks to run automatically on commits to PRs.

@engn33r engn33r merged commit ba3d754 into websocket-client:master Sep 11, 2023
10 checks passed
@engn33r
Copy link
Collaborator

engn33r commented Sep 11, 2023

Thank you for the helpful upgrade!

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.

Typing annotations should use | instead of or
2 participants