Skip to content

Type aliases to PEP 604 unions do not work, saying it's not valid as type #11280

Closed
@AMDmi3

Description

@AMDmi3

Bug Report

When I create a type alias to PEP604-style union type, mypy complains that it's "not valid as a type".

To Reproduce

MyType = str | None
myvar: MyType
mypy 1.py

Expected Behavior

No errors, the same output as for:

from typing import Optional
MyType = Optional[str]
myvar: MyType

Actual Behavior

1.py:2: error: Variable "1.MyType" is not valid as a type
1.py:2: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10
  • Operating system and version: FreeBSD 13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions