-
-
Notifications
You must be signed in to change notification settings - Fork 43
Add type hints #491
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
Add type hints #491
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
cf42df2 to
ce49866
Compare
|
Until python/typing#548 is settled, we cannot have fully generic functions |
|
@fabiocaccamo This is ready for review. Also inviting @pirate. |
pirate
left a comment
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.
spent 10 minutes spot-checking this PR and it looks good to me, cant promise I didn't miss anything though
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #491 +/- ##
==========================================
- Coverage 97.76% 97.68% -0.08%
==========================================
Files 63 63
Lines 2011 2246 +235
==========================================
+ Hits 1966 2194 +228
- Misses 45 52 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@fabiocaccamo The type stubs deps have to be in pre-commit config for Mypy to work. |
- Fix serializer type parameter order (JSON/Pickle: [Any,str] → [str,Any]). - Simplify XMLSerializer to return dict[str,Any] instead of OrderedDict. - Remove redundant type casts and unnecessary type ignores. - Add proper generic typing to core functions (filter, invert, merge, subset). - Improve type annotations for dict operations and return types. - Remove unused import statements and clean up type imports. - Add missing __future__ annotations imports where needed. - Fix type ignore comments to be more specific and necessary only.
name: Pull request
about: Submit a pull request for this project
assignees: fabiocaccamo
Describe your changes
Add type hints.
Notes:
Any._KPTtype used in__init__.pyis less than ideal but it covers all bases of what is possible to use for a key, but there are still some functions that extend from Keyattr and those must take_Kwhich defaults tostr.typing.cast()is used instead of type assertions to avoid the error from Codacy (which has the Bandit rule about assertions). Overhead is likely minimal vsassertcalls but the nice thing is they do get removed in optimised mode, so the overhead can be zero in that case. I see no real issue with assertions so if you want to use those instead ofcast()I can revise this. I think making a Bandit config file can quiet Codacy about the issue.I have tried this with my youtube-unofficial project and it works as expected.
The best way to use this is with typing is to add the type on assignment:
In the future the way to solve this is to have a
TypeBenedictto specify a schema, and then have a Mypy plugin that would resolve the actual type. This is similar to what the Mypy Django plugin does with database models.Related issue
Issue #157
Checklist before requesting a review