Skip to content

Missing update method on the CaseInsensitiveDict #7632

Closed

Description

@Fokko

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.

Activity

  1. AlexWaygood commented on Apr 16, 2022

    @AlexWaygood
    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 :)

  2. added a commit that references this issue on Apr 16, 2022
    9116deb
  3. Fokko commented on Apr 16, 2022

    @Fokko
    Author

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

  4. AlexWaygood commented on Apr 16, 2022

    @AlexWaygood
    Member

    #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 :)

  5. added a commit that references this issue on Apr 16, 2022
    66bea8c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions