-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
base: main
Are you sure you want to change the base?
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. |
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 ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #491 +/- ##
==========================================
- Coverage 97.76% 97.67% -0.09%
==========================================
Files 63 63
Lines 2011 2241 +230
==========================================
+ Hits 1966 2189 +223
- 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. |
name: Pull request
about: Submit a pull request for this project
assignees: fabiocaccamo
Describe your changes
Add type hints.
Notes:
Any
._KPT
type used in__init__.py
is 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_K
which 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 vsassert
calls 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
TypeBenedict
to 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