You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Optional and the new union syntax for the type argument to a class's generic superclass cause mypy to report different errors (none for Optional[T], two for T | None).
To Reproduce
The behaviour can be seen in this example, where A is the generic superclass, B uses Optional, and C uses the new type union syntax.
My expectation is that and Optional[T] and T | None are equivalent.
Actual Behavior
mypy reports the following for only the class using the union syntax:
$ mypy repro.py
repro.py:12: error: Type expected within [...]
class C(A[int | None]):
^
repro.py:12: error: Invalid base class "A"
class C(A[int | None]):
^
Found 2 errors in 1 file (checked 1 source file)
Your Environment
Mypy version used: 0.800
Mypy command-line flags: Occurs with --strict and without.
Python version used: 3.9.0
The text was updated successfully, but these errors were encountered:
Traceback (most recent call last):
File "/Users/robjwells/Dropbox/projects/adventofcode-solutions/2016/python/repro.py", line 12, in <module>
class C(A[int | None]):
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
Bug Report
Using
Optional
and the new union syntax for the type argument to a class's generic superclass cause mypy to report different errors (none forOptional[T]
, two forT | None
).To Reproduce
The behaviour can be seen in this example, where
A
is the generic superclass,B
uses Optional, andC
uses the new type union syntax.Expected Behavior
My expectation is that and
Optional[T]
andT | None
are equivalent.Actual Behavior
mypy reports the following for only the class using the union syntax:
Your Environment
--strict
and without.The text was updated successfully, but these errors were encountered: