Mypy is returning an error that I do not understand (nor can I recreate in a reduced form). Googling the error is proving difficult (given the question mark).
Does anyone know what this error means? Specifically what the question mark denotes?
Unsupported type Type[typeBasePage?]
The code in question:
typeBasePage = TypeVar("typeBasePage", bound="BasePage") # any instance subclass of BasePage
typeNavCls = Type[typeBasePage] # error occurs here - trying to make an alias
class Nav:
def __init__(self, cls: typeNavCls):
self.cls: typeNavCls = cls
class BasePage(Base):
...
# redacted because it's huge
Again, if I try to recreate the above code in a very reduced form, mypy doesn't error.
typeB = TypeVar('typeB', bound='B')
tAlias = Type[typeB]
class Nav:
def __init__(self, cls: tAlias):
self.cls: tAlias = cls
class A: pass
class B(A): pass
I believe I found what the question mark is, but am nowhere closer to figuring out why the error occurs in mypy.
https://mypy.readthedocs.io/en/latest/literal_types.html
If you do not provide an explicit type in the
Final
, the type ofc
becomes context-sensitive: mypy will basically try “substituting” the original assigned value whenever it’s used before performing type checking. This is why the revealed type ofc
isLiteral[19]?
: the question mark at the end reflects this context-sensitive nature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With