Skip to content

Missing update method on the CaseInsensitiveDict #7632

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

Closed
Fokko opened this issue Apr 16, 2022 · 3 comments · Fixed by #7634
Closed

Missing update method on the CaseInsensitiveDict #7632

Fokko opened this issue Apr 16, 2022 · 3 comments · Fixed by #7634

Comments

@Fokko
Copy link

Fokko commented Apr 16, 2022

We got mypy errors after the release 6 hours ago:

communication/slack/tasks.py:39: error: "CaseInsensitiveDict?[builtins.str]" has no attribute "update"

This is when we do (simplified):

session = requests.Session()
session.headers.update({"Authorization": f"Bearer {access_token}"})

Also part of the docs: https://docs.python-requests.org/en/master/user/advanced/

I think the CaseInsensitiveDict should also contain the .update() method. Will open a PR in a second.

@AlexWaygood
Copy link
Member

Thanks! The issue isn't that CaseInsensitiveDict doesn't have a .update() method, however — it does, it inherits it from MutableMapping. The issue is that CaseInsensitiveDict is currently marked as a TypeAlias assignment following 740193a#diff-bfcfcf0d08b5e5c2965394517079c5cfb2b2a11b2e27cf9d08fb07090cd9a4ceR32, meaning mypy is getting confused when you're trying to use it as a variable rather than as a type.

It's my mistake; I can send an alternative PR to fix it :)

@Fokko
Copy link
Author

Fokko commented Apr 16, 2022

Thanks for the quick response and the background info @AlexWaygood. Feel free to send an alternative PR; you're the expert here :)

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 16, 2022

#7634 should fix it, though I haven't tested it. I'm pretty sure the recent switch to using TypeAlias in more places was the cause, though :)

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 a pull request may close this issue.

2 participants