-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
featuretopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations
Description
Bug Report
This came up in testing for pandas-stubs.
If you have a list of lists of different types, mypy infers it as a list[object] rather than a list of the union of the lists of the inner types.
To Reproduce
class NAType:
pass
class NaTType:
pass
NA: NAType = NAType()
NaT: NaTType = NaTType()
foo = [[None], [NA], [NaT]]
reveal_type(foo)Expected Behavior
Revealed type is list[list[None] | list[NAType] | list[NaTType]]
This is what pyright returns with the setting strictListInference=True
Actual Behavior
Revealed type is "builtins.list[builtins.object]
Your Environment
- Mypy version used: 1.19.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.11
cmp0xff
Metadata
Metadata
Assignees
Labels
featuretopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations