Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[match-case] class pattern narrowing with Union-argument different from equivalentisinstance call. #19468

Open
Labels
bugmypy got something wrongtopic-match-statementPython 3.10's match statementtopic-type-narrowingConditional type narrowing / binder
@randolf-scholz

Description

@randolf-scholz
classFoo: ...classBar(Foo): ...deftest_1(bar:Bar)->None:matchbar:caseFoo()asfoo:reveal_type(foo)# N: Revealed type is "__main__.Bar"deftest_2(bar:Bar|str)->None:matchbar:caseFoo()asfoo:reveal_type(foo)# N: Revealed type is "__main__.Foo"deftest_3(bar:Bar)->None:ifisinstance(bar,Foo):reveal_type(bar)# N: Revealed type is "__main__.Bar"deftest_4(bar:Bar|str)->None:ifisinstance(bar,Foo):reveal_type(bar)# N: Revealed type is "__main__.Bar"

https://mypy-play.net/?mypy=latest&python=3.12&gist=4bc28e67967c7809ccdd0962f3372dd7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-match-statementPython 3.10's match statementtopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp