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
Mypy appears not to consider ImportError to be an exception type in some cases.
To Reproduce
y= [
# ValueError,ImportError, # error: List item 0 has incompatible type "Type[ImportError]"; expected "Type[Exception]" [list-item]AttributeError,
]
reveal_type(y) # note: Revealed type is "builtins.list[def (*args: builtins.object, *, name: Union[builtins.str, None] =, obj: Union[builtins.str, None] =) -> builtins.Exception]"
The ordering of the list elements doesn't seem to impact the behaviour.
If you un-comment the ValueError however:
y= [
ValueError,
ImportError,
AttributeError,
]
reveal_type(y) # note: Revealed type is "builtins.list[builtins.type]"
While this is perhaps less precise than I'd hope (I'd hop to get list[type[Exception]]) it feels more right to me.
Adding an annotation to the variable (y: list[type[Exception]]) does help mypy see that this is ok, however in my original use-case the list being constructed was passed to a decorator function, so there was no easy opportunity to annotate it.
Your Environment
Mypy version used: 0.991
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.11
The text was updated successfully, but these errors were encountered:
Bug Report
Mypy appears not to consider
ImportError
to be an exception type in some cases.To Reproduce
The ordering of the list elements doesn't seem to impact the behaviour.
If you un-comment the
ValueError
however:While this is perhaps less precise than I'd hope (I'd hop to get
list[type[Exception]]
) it feels more right to me.Adding an annotation to the variable (
y: list[type[Exception]]
) does helpmypy
see that this is ok, however in my original use-case the list being constructed was passed to a decorator function, so there was no easy opportunity to annotate it.Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: