[match-case] fix matching against typing.Callable and Protocol types.#19471
Merged
ilevkivskyi merged 23 commits intopython:masterfrom Oct 16, 2025
Merged
[match-case] fix matching against typing.Callable and Protocol types.#19471ilevkivskyi merged 23 commits intopython:masterfrom
typing.Callable and Protocol types.#19471ilevkivskyi merged 23 commits intopython:masterfrom
Conversation
…eckable test should be performed elsewhere.
…on and anonymous `Callable`
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
39eedb4 to
74db0aa
Compare
This comment has been minimized.
This comment has been minimized.
3418149 to
d62d6d2
Compare
This comment has been minimized.
This comment has been minimized.
d62d6d2 to
143f990
Compare
This comment has been minimized.
This comment has been minimized.
sterliakov
reviewed
Jul 27, 2025
Collaborator
|
Also, does this fix #19470 completely or partially? Please update the description to either remove "partially" or remove "fixes" magic word, so that half-resolved issue does not get autoclosed |
Co-authored-by: Stanislav Terliakov <50529348+sterliakov@users.noreply.github.com>
Co-authored-by: Stanislav Terliakov <50529348+sterliakov@users.noreply.github.com>
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This was referenced Oct 6, 2025
Closed
sterliakov
approved these changes
Oct 11, 2025
Collaborator
sterliakov
left a comment
There was a problem hiding this comment.
Thanks! I like your docstring suggestion in the last comment, could you merge it?
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
@sterliakov done. |
ilevkivskyi
approved these changes
Oct 16, 2025
Member
ilevkivskyi
left a comment
There was a problem hiding this comment.
OK, looks like this is something worth trying
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/http.py:607: error: Unused "type: ignore" comment [unused-ignore]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
collection.abc.Callableraises error [misc] #14014AnyCallableProtocol differs fromcallable()check #19470Added extra logic in
checker.py:conditional_typesfunction to deal with structural types such astyping.Callableor protocols.new tests
testMatchClassPatternCallable: testscase Callable() as fnusagetestMatchClassPatternProtocol: testscase Proto()usage, whereProtois a ProtocoltestMatchClassPatternCallbackProtocol: testscase Proto()usage, whereProtois a Callback-ProtocoltestGenericAliasIsinstanceUnreachable: derived from a mypy-primer failure in mesonbuild. Tests thatisinstance(x, Proto)can produce unreachable error.testGenericAliasRedundantExprCompoundIfExpr: derived from a CI failure ofpython runtest.py selfof an earlier version of this PR.modified tests
testOverloadOnProtocoladded annotations to overload implementation, which wasn't getting checked. Added missing return. Fixed return type in second branch.