-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Narrow types based on collection containment #20602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
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]
|
|
The setuptools regression is: 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 |
There was a problem hiding this comment.
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
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