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

False-positive error when usingCallable in a PEP 604 type alias in a stub file with--python-version=3.9 #14158

Closed
Assignees
JukkaL
Labels
affects-typeshedAnything that blocks a typeshed changebugmypy got something wrongfalse-positivemypy gave an error on correct codetopic-pep-604PEP 604 (union | operator)topic-type-aliasTypeAlias and other type alias issues
@AlexWaygood

Description

@AlexWaygood

Bug Report

In a stub file, with--python-version=3.9, mypy emits false positive errors for the following type aliases:

fromtypingimportCallablefromtyping_extensionsimportTypeAliasX=int|Callable[[],str|bool]XX:TypeAlias=int|Callable[[],str|bool]Y=int|Callable[[str|bool],str]YY:TypeAlias=int|Callable[[str|bool],str]

For all of these, mypy's error message is:

error: Unsupported left operand type for | ("Type[str]")  [operator]

Note that this snippet works fine in a.py or.pyi file with--python-version 3.10. It's only--python-version 3.9 with a.pyi file that has the bug.

To Reproduce

  1. cd into an up-to-date local clone of mypy with an editable install.
  2. Copy the above snippet into atest.pyi file.
  3. Runmypy test.pyi --python-version 3.9

Expected Behavior

No error should be emitted. PEP 604 syntax should be legal in stub files, even with--python-version 3.9.

Actual Behavior

False-positive errors are emitted.

Your Environment

  • Mypy version used:c660354
  • Mypy command-line flags:--python-version 3.9
  • Python version used: 3.10

Cc.@ilevkivskyi (x-ref#12393).

Metadata

Metadata

Assignees

Labels

affects-typeshedAnything that blocks a typeshed changebugmypy got something wrongfalse-positivemypy gave an error on correct codetopic-pep-604PEP 604 (union | operator)topic-type-aliasTypeAlias and other type alias issues

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp