Skip to content

Conversation

@hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Jan 16, 2026

Test cases come from #17344 authored by Jordandev678

We've wanted to do this for a long time, but previous attempt was reverted due to issues like #17841 , #17864 , #17869

Following #20492 we should now be in a position to do this narrowing

Fixes #3229
Fixes #20234
Fixes #18208
Fixes #16774

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

spark (https://github.com/apache/spark)
+ python/pyspark/pandas/utils.py:755: error: Redundant cast to "int"  [redundant-cast]

mypy (https://github.com/python/mypy)
+ mypy/constraints.py:266: error: Argument "arg_kinds" to "Parameters" has incompatible type "list[Literal[ArgKind.ARG_POS, ArgKind.ARG_STAR, ArgKind.ARG_STAR2]]"; expected "list[ArgKind]"  [arg-type]
+ mypy/constraints.py:266: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ mypy/constraints.py:266: note: Consider using "Sequence" instead, which is covariant
+ mypyc/irbuild/util.py:141: error: Redundant cast to "Literal['native_class', 'allow_interpreted_subclasses', 'serializable', 'free_list_len']"  [redundant-cast]
+ mypyc/irbuild/util.py:141: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-cast for more info

altair (https://github.com/vega/altair)
+ tools/versioning.py:258: error: Unused "type: ignore" comment  [unused-ignore]

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/context/menu.py:144: error: Incompatible return value type (got "CommandType", expected "Literal[CommandType.USER, CommandType.MESSAGE]")  [return-value]

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/addons/core.py:172: error: Unused "type: ignore" comment  [unused-ignore]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/csgo/state.py:213: error: Argument 1 to "__delitem__" of "dict" has incompatible type "int"; expected "AssetID"  [arg-type]
- steam/ext/csgo/state.py:214: error: Argument 1 to "__delitem__" of "dict" has incompatible type "int"; expected "AssetID"  [arg-type]

setuptools (https://github.com/pypa/setuptools)
+ setuptools/_shutil.py:39: error: Incompatible return value type (got "None", expected "_T")  [return-value]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/io/stata.py:1437: error: Redundant cast to "str"  [redundant-cast]
+ pandas/io/stata.py:1797: error: Redundant cast to "str"  [redundant-cast]
+ pandas/io/stata.py:1803: error: Redundant cast to "str"  [redundant-cast]

discord.py (https://github.com/Rapptz/discord.py)
+ discord/components.py:1464: error: Unused "type: ignore" comment  [unused-ignore]
+ discord/app_commands/models.py:900: error: Unused "type: ignore" comment  [unused-ignore]
+ discord/threads.py:286: error: Unused "type: ignore" comment  [unused-ignore]
+ discord/state.py:693: error: Unused "type: ignore" comment  [unused-ignore]

archinstall (https://github.com/archlinux/archinstall)
+ archinstall/lib/menu/list_manager.py:86: error: Redundant cast to "str"  [redundant-cast]

rotki (https://github.com/rotki/rotki)
+ rotkehlchen/types.py:1278: error: Unused "type: ignore" comment  [unused-ignore]
+ rotkehlchen/types.py:1286: error: Unused "type: ignore" comment  [unused-ignore]
+ rotkehlchen/chain/ethereum/utils.py:90: error: Unused "type: ignore" comment  [unused-ignore]
+ rotkehlchen/inquirer.py:976: error: Redundant cast to "Literal[ChainID.ETHEREUM, ChainID.POLYGON_POS, ChainID.OPTIMISM, ChainID.ARBITRUM_ONE, ChainID.GNOSIS, ChainID.BASE, ChainID.BINANCE_SC]"  [redundant-cast]
+ rotkehlchen/tasks/assets.py:459: error: Unused "type: ignore[arg-type]" comment  [unused-ignore]
+ rotkehlchen/chain/aggregator.py:1187: error: Unused "type: ignore" comment  [unused-ignore]
+ rotkehlchen/rotkehlchen.py:739: error: Unused "type: ignore" comment  [unused-ignore]
+ rotkehlchen/rotkehlchen.py:744: error: Unused "type: ignore" comment  [unused-ignore]
+ rotkehlchen/rotkehlchen.py:1017: error: Redundant cast to "Literal[SupportedBlockchain.ETHEREUM, SupportedBlockchain.OPTIMISM, SupportedBlockchain.POLYGON_POS, SupportedBlockchain.ARBITRUM_ONE, SupportedBlockchain.BASE, SupportedBlockchain.GNOSIS, SupportedBlockchain.SCROLL, SupportedBlockchain.BINANCE_SC]"  [redundant-cast]
+ rotkehlchen/api/services/transactions.py:125: error: Unused "type: ignore" comment  [unused-ignore]
+ rotkehlchen/api/services/transactions.py:126: error: "ChainManagerWithTransactions[Any]" has no attribute "node_inquirer"  [attr-defined]
+ rotkehlchen/api/services/transactions.py:240: error: Redundant cast to "Literal[SupportedBlockchain.ETHEREUM, SupportedBlockchain.OPTIMISM, SupportedBlockchain.POLYGON_POS, SupportedBlockchain.ARBITRUM_ONE, SupportedBlockchain.BASE, SupportedBlockchain.GNOSIS, SupportedBlockchain.SCROLL, SupportedBlockchain.BINANCE_SC] | Literal[SupportedBlockchain.SOLANA]"  [redundant-cast]
+ rotkehlchen/api/services/transactions.py:589: error: Unused "type: ignore" comment  [unused-ignore]

xarray (https://github.com/pydata/xarray)
+ xarray/core/dataset.py: note: In member "pad" of class "Dataset":
+ xarray/core/dataset.py:9084: error: Incompatible types in assignment (expression has type "Literal['constant']", variable has type "Literal['edge', 'reflect', 'symmetric', 'wrap']")  [assignment]

@hauntsaninja
Copy link
Collaborator Author

hauntsaninja commented Jan 16, 2026

The setuptools regression is:

import os
from typing import Callable, TypeVar
T = TypeVar("T")
def auto_chmod(func: Callable[..., T], arg: str) -> T:
    if func in [os.unlink, os.remove]:
        return func(arg)
    raise

The xarray regression is just a redefinition issue, now that we have narrowed to Literal

narrowable_indices={0},
)

# We only try and narrow away 'None' for now
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is actually not really needed anymore. I will clean it up, there is one test case affected, a later PR in my stack changes it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant