Skip to content

False positive for PEP 604 None | t when used as value #12368

Closed
@NiklasRosenstein

Description

@NiklasRosenstein

Bug Report

Using None | t instead of t | None prompts an error when used as a value (not a type hint).

https://peps.python.org/pep-0604/#proposal

To Reproduce

a: None | int
b = None | int  # error: Unsupported left operand type for | ("None")  [operator]

Expected Behavior

Mypy does not complain about the second line.

Your Environment

  • Mypy version used: 90.940
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
    pretty = true
    namespace_packages = true
    warn_redundant_casts = true
    warn_no_return = true
    warn_unreachable = true
    show_error_context = true
    show_error_codes = true
    check_untyped_defs = true
  • Python version used: 3.10.2
  • Operating system and version: Ubuntu 20.04 WSL

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-604PEP 604 (union | operator)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions