Uh oh!
There was an error while loading. Please reload this page.
Narrow type variable bounds in binder - #19183
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ilevkivskyi
commented
May 31, 2025
OK, the |
hauntsaninja
commented
Jun 1, 2025
Hooray! |
Diff from mypy_primer, showing the effect of this PR on open source code: PyGithub (https://github.com/PyGithub/PyGithub)
+ github/MainClass.py:988: error: Unused "type: ignore" comment [unused-ignore]
antidote (https://github.com/Finistere/antidote): 1.47x slower (65.5s -> 96.3s in single noisy sample)
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/states.py:369: error: Argument 1 to "StateGroup" has incompatible type "Collection[Union[State[Any], Any]]"; expected "list[State[Any]]" [arg-type]+ src/prefect/states.py:369: error: Argument 1 to "StateGroup" has incompatible type "Collection[Never]"; expected "list[State[Any]]" [arg-type]+ src/prefect/futures.py:222: note: def result(self, raise_on_failure: Literal[True] = ..., retry_result_failure: bool = ...) -> Any+ src/prefect/futures.py:222: note: def result(self, raise_on_failure: Literal[False] = ..., retry_result_failure: bool = ...) -> Union[Any, Exception]+ src/prefect/futures.py:222: note: def result(self, raise_on_failure: bool = ..., retry_result_failure: bool = ...) -> Union[Any, Exception]- src/prefect/task_engine.py:467: error: Item "type" of "Union[ResultRecord[Any], type[NotSet]]" has no attribute "result" [union-attr]+ src/prefect/task_engine.py:467: error: Item "type" of "Union[R, type[NotSet]]" has no attribute "result" [union-attr]- src/prefect/task_engine.py:1022: error: Item "type" of "Union[ResultRecord[Any], type[NotSet]]" has no attribute "result" [union-attr]+ src/prefect/task_engine.py:1022: error: Item "type" of "Union[R, type[NotSet]]" has no attribute "result" [union-attr]- src/prefect/flow_runs.py:292: error: Item "type" of "Union[type[AutomaticRunInput[Never]], type[T]]" has no attribute "load" [union-attr]+ src/prefect/flow_runs.py:292: error: "type[T]" has no attribute "load" [attr-defined]- src/prefect/flow_runs.py:307: error: Item "type" of "Union[type[AutomaticRunInput[Never]], type[T]]" has no attribute "save" [union-attr]+ src/prefect/flow_runs.py:307: error: "type[T]" has no attribute "save" [attr-defined]- src/prefect/flow_runs.py:319: error: Item "type" of "Union[type[AutomaticRunInput[Never]], type[T]]" has no attribute "load" [union-attr]+ src/prefect/flow_runs.py:319: error: "type[T]" has no attribute "load" [attr-defined]- src/prefect/flow_runs.py:446: error: Item "type" of "Union[type[AutomaticRunInput[Never]], type[T]]" has no attribute "load" [union-attr]+ src/prefect/flow_runs.py:446: error: "type[T]" has no attribute "load" [attr-defined]- src/prefect/flow_runs.py:456: error: Item "type" of "Union[type[AutomaticRunInput[Never]], type[T]]" has no attribute "save" [union-attr]+ src/prefect/flow_runs.py:456: error: "type[T]" has no attribute "save" [attr-defined]
kopf (https://github.com/nolar/kopf)
+ kopf/_cogs/structs/dicts.py:243: error: Unused "type: ignore" comment [unused-ignore]+ kopf/_core/intents/handlers.py:36: error: Redundant cast to "execution.CauseT" [redundant-cast]
python-chess (https://github.com/niklasf/python-chess)
- chess/pgn.py:1315: error: Returning Any from function declared to return "HeadersT" [no-any-return]
kornia (https://github.com/kornia/kornia)
+ kornia/utils/helpers.py:387: error: Unused "type: ignore" comment [unused-ignore]
mypy (https://github.com/python/mypy)
+ mypy/expandtype.py:125: error: Redundant cast to "F" [redundant-cast]+ mypy/expandtype.py:125: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-cast for more info+ mypy/typeops.py:421: error: Redundant cast to "F" [redundant-cast]+ mypy/typeops.py:430: error: Redundant cast to "F" [redundant-cast]+ mypy/typeops.py:469: error: Incompatible types in assignment (expression has type "CallableType", variable has type "F") [assignment]+ mypy/typeops.py:484: error: Redundant cast to "F" [redundant-cast]+ mypy/checkmember.py:1489: error: Redundant cast to "F" [redundant-cast]+ mypy/checkmember.py:1492: error: Redundant cast to "F" [redundant-cast]+ mypy/checkmember.py:1502: error: Redundant cast to "F" [redundant-cast]
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/third_party/beartype.py:128: error: Incompatible types in assignment (expression has type "_T", variable has type "type[Any]") [assignment]+ src/hydra_zen/third_party/beartype.py:128: error: Incompatible types in assignment (expression has type "_T", variable has type "_T") [assignment]+ src/hydra_zen/third_party/beartype.py:130: error: Redundant cast to "_T" [redundant-cast]+ src/hydra_zen/third_party/pydantic.py:111: error: Redundant cast to "_T" [redundant-cast]+ src/hydra_zen/third_party/pydantic.py:115: error: Redundant cast to "_T" [redundant-cast]- src/hydra_zen/third_party/pydantic.py:123: error: Argument 1 has incompatible type "_T | type[object]"; expected "_T" [arg-type]
pytest (https://github.com/pytest-dev/pytest)
- src/_pytest/fixtures.py:1132: error: Returning Any from function declared to return "FixtureValue" [no-any-return]
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ tests/__init__.py:67: error: Unused "type: ignore" comment [unused-ignore]+ tests/__init__.py:85: error: Unused "type: ignore" comment [unused-ignore]
beartype (https://github.com/beartype/beartype)
+ beartype/_decor/_type/decortype.py:133: error: Unused "type: ignore" comment [unused-ignore]+ beartype/_decor/_type/decortype.py:295: error: Unused "type: ignore" comment [unused-ignore]+ beartype/_decor/_nontype/decornontype.py:294: error: Unused "type: ignore" comment [unused-ignore]+ beartype/_decor/_nontype/decornontype.py:301: error: Unused "type: ignore" comment [unused-ignore]+ beartype/_decor/_nontype/decornontype.py:380: error: Unused "type: ignore" comment [unused-ignore]+ beartype/_decor/_nontype/decornontype.py:395: error: Unused "type: ignore" comment [unused-ignore]+ beartype/_decor/_nontype/decornontype.py:567: error: Unused "type: ignore" comment [unused-ignore]+ beartype/_decor/decorcore.py:133: error: Unused "type: ignore" comment [unused-ignore]
xarray (https://github.com/pydata/xarray)
+ xarray/structure/alignment.py: note: In function "_broadcast_helper":+ xarray/structure/alignment.py:1140: error: Redundant cast to "T_Alignable" [redundant-cast]+ xarray/structure/alignment.py:1142: error: Redundant cast to "T_Alignable" [redundant-cast]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/commands.py:284: error: Argument 1 to "append" of "list" has incompatible type "Command[Any, Any, Any]"; expected "Self" [arg-type]- steam/ext/commands/cog.py:182: error: Argument 1 to "decorator" has incompatible type "Callable[[Any | None, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"; expected "F" [arg-type]- steam/ext/commands/bot.py:415: error: Argument 1 to "decorator" has incompatible type "Callable[..., Coroutine[Any, Any, Any]]"; expected "F" [arg-type] |
ftr: this commit fixes a bug we encountered with mypy 1.16.0 (and not in 1.15.0) in different places with a stacktrace like: |
ilevkivskyi
commented
Jun 11, 2025
@netomi Hm, this is interesting, could you please post a full traceback? (use |
that is already with this option: the project can be found here: https://github.com/apache/infrastructure-asfyaml it is now using 1.15.0, but updating to 1.16.0 shows the bug. |
ilevkivskyi
commented
Jun 14, 2025
A bit more of the traceback This looks like something where I would say this PR may be indeed a proper fix. So looks like no action needed (apart from releasing 1.17 LOL) |
netomi
commented
Jun 14, 2025
just wanted to mention it as there might be others that report issues about that, so there should be a changelog entry to track that this is solved in 1.17.0 imho. |
Fixes#5720
Fixes#8556
Fixes#9778
Fixes#10003
Fixes#10817
Fixes#11163
Fixes#11664
Fixes#12882
Fixes#13426
Fixes#13462
Fixes#14941
Fixes#15151
Fixes#19166
This handles a (surprisingly) common edge case. The charges in
bind_self()andbind_self_fast()are tricky. I got a few "Redundant cast" errors there, which seemed good, but then I realized that attribute access etc. on a type variable go through slowPyObjectpaths, so I am actually forcingCallableTypeinstead ofF(bound=CallableType)there, since these are performance-critical functions.