Skip to content
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

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

Closed
AMDmi3 opened this issue Oct 6, 2021 · 2 comments
Closed
Labels
bug mypy got something wrong

Comments

@AMDmi3
Copy link

AMDmi3 commented Oct 6, 2021

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
@AMDmi3 AMDmi3 added the bug mypy got something wrong label Oct 6, 2021
@JelleZijlstra
Copy link
Member

I think this got fixed on master, let me check.

@JelleZijlstra
Copy link
Member

#10770

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants