Skip to content

requests: allow non-mutable Mapping for files/hooks parameters - #7732

Merged
AlexWaygood merged 1 commit into
python:masterfrom
milanboers:requests-sessions-fix
Apr 28, 2022
Merged

AlexWaygood merged 1 commit into
python:masterfrom
milanboers:requests-sessions-fix

Conversation

@milanboers

Copy link
Copy Markdown
Contributor

Another one 😒 still an issue with #7724 . Problem is MutableMapping is invariant, so the union type will actually never match.
Changed it to Mapping (which is covariant in the value type) now. It doesn't seem to be mutated anywhere, I also passed frozendict to try. Also tried assigning a dict[str, BufferedReader] to it as in the issue, which passes the type check now.

Same problem would occur in _Hooks, so changed that one too. Kept _TextMapping as-is because it requires str (would still fail on a subtype of str).

@AlexWaygood

AlexWaygood commented Apr 28, 2022 •

Copy link
Copy Markdown
Member

Thanks for all your work on this!

@shawnwall

Copy link
Copy Markdown

thank you! i tried digging but am not well versed in the ways of how tests work in typeshed, but shouldn't we try to get some test cases in place regarding these types of files= usages to make sure we are all covered in future?

@Akuli

Akuli commented Apr 28, 2022

Copy link
Copy Markdown
Collaborator

Typeshed doesn't do much tests in the usual sense. There has been a lot of discussion about this, but in short, we don't want to duplicate information that is already specified in the stubs.

For standard library stubs, we have mypy-primer, which runs mypy across many open-source projects on each new PR and posts a diff of mypy outputs as a comment. It would work very well for problems like this. Unfortunately it is currently not being used for third-party stubs, see hauntsaninja/mypy_primer#7.

@JelleZijlstra

Copy link
Copy Markdown
Member

Though we do have a few assert_type()-based tests now, and we could start adding more.

@brandonchinn178

Copy link
Copy Markdown

FYI This breaks session.hooks['response'] = ... #7776

@Akuli

Akuli commented May 18, 2022

Copy link
Copy Markdown
Collaborator

Unfortunately it is currently not being used for third-party stubs

Now it is, and regressions like this are much less likely to happen: hauntsaninja/mypy_primer#31

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 this pull request may close these issues.

6 participants