Skip to content

[match-case] fix matching against typing.Callable and Protocol types. #19471

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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
split Callback test into two.
  • Loading branch information
randolf-scholz committed Jul 17, 2025
commit 89f8350478aab1d48263cde1c36fdbe5de1113f9
24 changes: 22 additions & 2 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ def test_object(x: object) -> None:
case Callable() as fn:
reveal_type(fn) # N: Revealed type is "def (*Any, **Any) -> Any"

def test_intfun(x: Callable[[int], int]) -> None:
def test_impl(x: Callable[[int], int]) -> None:
match x:
case Callable() as fn:
reveal_type(fn) # N: Revealed type is "def (builtins.int) -> builtins.int"
Expand All @@ -1087,6 +1087,26 @@ def test_intfun(x: Callable[[int], int]) -> None:
from typing import Any, Callable
from typing_extensions import Protocol, runtime_checkable

@runtime_checkable
class FnProto(Protocol):
def __call__(self, x: int, /) -> object: ...

def test_object(x: object) -> None:
match x:
case FnProto() as fn:
reveal_type(fn) # N: Revealed type is "__main__.FnProto"

def test_impl(x: Callable[[int], int]) -> None:
match x:
case FnProto() as fn:
reveal_type(fn) # N: Revealed type is "def (builtins.int) -> builtins.int"

[builtins fixtures/dict.pyi]

[case testMatchClassPatternAnyCallableProtocol]
from typing import Any, Callable
from typing_extensions import Protocol, runtime_checkable

@runtime_checkable
class AnyCallable(Protocol):
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
Expand All @@ -1096,7 +1116,7 @@ def test_object(x: object) -> None:
case AnyCallable() as fn:
reveal_type(fn) # N: Revealed type is "__main__.AnyCallable"

def test_intfun(x: Callable[[int], int]) -> None:
def test_impl(x: Callable[[int], int]) -> None:
match x:
case AnyCallable() as fn:
reveal_type(fn) # N: Revealed type is "def (builtins.int) -> builtins.int"
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy