-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Introduce AppKey for type safety #6498
Conversation
for more information, see https://pre-commit.ci
If it makes linter problems, we can drop inheritance from |
I'll just drop a |
So, it doesn't work as nicely as I'd like.
Another issue is that the typing errors from mypy are rather difficult to work with. For example, this code in aiohttp-jinja2:
Produces:
But, it works if you write it as:
Even with simple examples like:
Mypy just produces: Which is rather awkward for the user to figure out the problem. The type of both items is defined as a |
Anyway, changes for aiohttp-jinja2: https://github.com/aio-libs/aiohttp-jinja2/pull/534/files |
Weirdly, mypy stop complaining about this once the parameter is defined with |
This pull request introduces 2 alerts when merging a7cd6b7 into 30e9d7f - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging 5c9aa9c into 30e9d7f - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging de82d2b into 30e9d7f - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging 7fbdff9 into 30e9d7f - view on LGTM.com new alerts:
|
Codecov Report
@@ Coverage Diff @@
## master #6498 +/- ##
==========================================
- Coverage 93.36% 93.34% -0.03%
==========================================
Files 104 104
Lines 30496 30623 +127
Branches 3067 3080 +13
==========================================
+ Hits 28472 28584 +112
- Misses 1850 1863 +13
- Partials 174 176 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
for more information, see https://pre-commit.ci
This pull request introduces 2 alerts when merging 4a38645 into 58da337 - view on LGTM.com new alerts:
|
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.
LGTM.
@Dreamsorcerer please feel free to merge when you decide that the PR is ready.
Right, I'm going to merge this and hope that mypy improves its error message in future. I opened an issue for it: python/mypy#12012 |
Backport to 3.9: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply a1d4dac on top of patchback/backports/3.9/a1d4dac1d63ad64295d357c8097650e1ef63b9c9/pr-6498 Backporting merged PR #6498 into master
🤖 @patchback |
What if I don't care about types (because I'm using Python, not Typescript)?
Without having to figure out why my app is warning about AppKeys etc.? |
Firstly, it's a warning, just filter it out if you decide it's not relevant for you. Secondly, it's not possible to create a warning in mypy for something like this (especially retroactively, while maintaining backwards-compatibility). I'll add a note to that section with examples to filter out the warning, but it's just a standard warning. We added a custom class, so you can filter out that specific warning very easily. |
Also, even if you don't use mypy, a lot of users still want annotations etc. in their IDE via pyright or similar. |
Thanks for your response!
To do that I have to figure out what the warning means, and whether it's something that I need to fix. In this case the fix (using a WebKey class when both setting and retrieving, and figuring out types for values which would then need to be maintained) seems quite un-pythonic and would make the code more mysterious. I did already try to filter it out before posting here (I didn't previously know if filtering warnings was possible in Python) but the following code taken from SO didn't work
As I now have learned that you need to set up the 'ignore' before I just think that this is something that should be highlighted as best practices in the documentation and doesn't merit a warning. |
Works fine for me. Anyway, if you don't care at all, filter it globally, examples in the above link. I'd use catch_warnings() if you're only trying to maintain backwards-compatibility with something (which is likely what homeassistant will be doing). |
My version is 3.9.0b0 which doesn't appear to have #7677 in it "Only display warning when using -Wdefault, -We, -X dev or similar." So basically my 'observations' are redundant I think (I didn't have warnings explicitly turned on). |
Ah, yes, I didn't realise your were on b0. I did mention that the warning shouldn't appear unless you're explicitly enabling them with rc0 is building now. |
I apologize for wasting your time, |
Will create some PRs in other projects shortly to test it all out properly. But, this looks promising so far. It's less intrusive than the previous proposal and still works with
Request.config_dict
.