-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
When I create a type alias to PEP604-style union type, using a type from a package without type annotations, mypy complains that it's "not valid as a type".
Similar to #11280, but using a class from an untyped package.
Interestingly, things work if I explicitly use str | Any.
To Reproduce
from shapely.geometry import BaseGeometry
b = str | BaseGeometry
my_var: bExpected Behavior
No error. Mypy should treat BaseGeometry like Any.
Actual Behavior
test.py:4: error: Variable "test.b" is not valid as a type [valid-type]
test.py:4: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.6.1
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.10.10
Workaround
Explicitly annotate variable as TypeAlias.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong