GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improved `Literal?` types by randolf-scholz · Pull Request #20444 · python/mypy

Conversation

@randolf-scholz

@randolf-scholz randolf-scholz commented Dec 19, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR aims to formalize the behavior of Literal? types (Instance with last_known_value) by treating them as-if they were AnyOf-types (see python/typing#566).

See #19625 for a thorough specification.

For example, Literal["x"]? is treated as-if it were AnyOf[str, Literal["x"]].

  • Fixes Specify behavior for Literal? types. #19625
  • Fixes meet_types gives unexpected results when meeting literal and Instance #19560
  • Fixes Regression: false positive avoid redundant cast with literal union #19055
  • Fixes mypy cannot decide if a cast is necessary or redundant #21607
  • Fixes Type Narrowing: if val == Literal should always narrow to Literal #16819
  • Fixes Narrowing types to Literal using in syntax #12535
  • Fixes Literal typeguard #10028
  • Fixes TypedDict item insertion support #5359

New Tests

  • JoinSuite.test_mixed_literal_types tests join between Literal? and other types.
  • MeetSuite.test_mixed_literal_types tests meet between Literal? and other types
  • TypeOpsSuite.test_simplified_union_with_mixed_str_literals2 tests simplified unions containing Literal? types
  • SubtypingSuite.test_literal tests subtype checks with Literal? types
  • RestrictionSuite: new test suite for testing the restrict_subtype_away method.
  • testJoinLiteralInstanceAndEnum tests join between Literal? and StrEnum

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@randolf-scholz
better support for literal? types
0e09a61
@randolf-scholz randolf-scholz mentioned this pull request Dec 19, 2025
Fix meet_types for literal and instance #19605
Closed
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz
randolf-scholz marked this pull request as draft December 20, 2025 13:22
@randolf-scholz

randolf-scholz commented Dec 20, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Repro of the operator issue:

from typing import Literal, reveal_type

class Port:
    protocol: Literal["tcp", "udp", "icmp"]
    port: int | None

def show(*ports: int | Port) -> None:
    # master: set[tuple[L['tcp', 'udp', 'icmp'], int | None]]
    # PR:     set[tuple[L['tcp']?, int] | tuple[L['tcp', 'udp', 'icmp'], int | None]]
    reveal_type(  
        {         
            ( "tcp", port ) if isinstance(port, int) else ( port.protocol, port.port )
            for port in ports
        }
    )

On master the set comprehension combines both branches into set[tuple[L['tcp', 'udp', 'icmp'], int | None]].
With this PR, Literal['tcp']? is a subtype but not a proper subtype of Literal['tcp'], so the tuples are not simplified away in make_simplified_union, which checks proper subtyping. For context, here are other type checker results:

checker result
mypy master set[tuple[L['tcp', 'udp', 'icmp'], int | None]]
mypy PR set[tuple[L['tcp']?, int] | tuple[L['tcp', 'udp', 'icmp'], int | None]]
pyright set[tuple[str, int] | tuple[str, int | None]]
ty set[tuple[str, int | None] | unknown]
pyrefly set[tuple[str, int] | tuple[str, int | None]]

RFC: would this be considered a regression, or is the behavior proposed by the PR OK?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@randolf-scholz
randolf-scholz marked this pull request as ready for review December 21, 2025 12:26
randolf-scholz
randolf-scholz commented Dec 21, 2025
View reviewed changes
Comment thread mypy/typeops.py
Comment on lines +613 to +621
# Step 5: Combine Literals and Instances with LKVs, e.g. Literal[1]?, Literal[1] -> Literal[1]?
proper_items: list[ProperType] = [get_proper_type(t) for t in simplified_set]
last_known_values: list[LiteralType | None] = [
p_t.last_known_value if isinstance(p_t, Instance) else None for p_t in proper_items
]
simplified_set = [
item for item, p_t in zip(simplified_set, proper_items) if p_t not in last_known_values
]

@randolf-scholz randolf-scholz Dec 21, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

Maybe it's possible to do something smarter here, so that e.g. list[Literal["x"]] and list[Literal["x"]?] would be combined as well

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@davidhalter davidhalter Dec 21, 2025

Copy link
Copy Markdown

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.

Just in case you're interested, I have implicit literals implemented as well in Zuban. However it works in a different way, I store the implicit information on the literal. This makes it a bit easier to deal with literals in my opinion. I understand that that might cause a lot of changes in Mypy and it also might cause other issues, but I feel like it's a bit better to store it that way, because it essentially is a literal.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

randolf-scholz reacted with eyes emoji
All reactions
  • 👀 1 reaction
@randolf-scholz

randolf-scholz commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

Update: The operator issue could be patched by a logical change in typeshed: python/typeshed#15160

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@randolf-scholz randolf-scholz mentioned this pull request Jan 16, 2026
Misleading error message with dict.get like method. (polymorphic function with conflicting context) #20576
Open
@randolf-scholz
Merge branch 'master' into literals_as_anyof_types
6101a57
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz randolf-scholz mentioned this pull request Jan 19, 2026
str.split v. LiteralString false positive type error. pyrefly-org/pyrefly#1766
Open
randolf-scholz added 2 commits February 2, 2026 21:06
@randolf-scholz
Merge branch 'master' into literals_as_anyof_types
76eb7ce
@randolf-scholz
Merge branch 'master' into literals_as_anyof_types
0260762
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz
randolf-scholz marked this pull request as draft February 3, 2026 08:53
@randolf-scholz

randolf-scholz commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

Converting to draft since recent changes give "Non-overlapping equality check" errors.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

randolf-scholz added 2 commits February 3, 2026 10:01
@randolf-scholz
updated test-data
d7fe600
@randolf-scholz
fixed incompatibility with FlipFlop test-case
80d2bed
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz
added type hint for mypyc
96da68d
@randolf-scholz

This comment was marked as outdated.

Sign in to view
@randolf-scholz

This comment was marked as outdated.

Sign in to view
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz
cleanup + fix meet with NamedTuple
377a0af
@github-actions

This comment has been minimized.

Sign in to view
randolf-scholz added 2 commits February 3, 2026 13:01
@randolf-scholz
rewrote ternary statement as separate returns for mypyc
cea2af9
@randolf-scholz
Merge branch 'master' into literals_as_anyof_types
ef22b69
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz
explicit is None check for mypyc
f2b855c
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz
Merge branch 'master' into literals_as_anyof_types
8d53181
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz randolf-scholz mentioned this pull request Mar 8, 2026
Remove list.__add__ overloads. python/typeshed#14282
Open
@randolf-scholz
Merge branch 'master' into literals_as_anyof_types
8dfa9d6
@github-actions

This comment has been minimized.

Sign in to view
@hauntsaninja
Merge branch 'master' into literals_as_anyof_types
da5727b
@github-actions

This comment has been minimized.

Sign in to view
@CNTRL-tek91 CNTRL-tek91 mentioned this pull request Aug 3, 2026
mypy cannot decide if a cast is necessary or redundant #21607
Open
@randolf-scholz
Merge branch 'master' into literals_as_anyof_types
45ccb3a
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz
Update type reveal comments in tests for Literal types
3497ec1
@github-actions

This comment has been minimized.

Sign in to view
@randolf-scholz
randolf-scholz marked this pull request as ready for review August 26, 2026 05:55
@github-actions github-actions Bot mentioned this pull request Aug 26, 2026
Check #20444 sterliakov/mypy-issues#310
Open
@hauntsaninja hauntsaninja added the upnext label Oct 21, 2026
@randolf-scholz
Merge branch 'master' into literals_as_anyof_types
748c834
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
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:757: error: Unused "type: ignore" comment  [unused-ignore]
- python/pyspark/pandas/groupby.py:3530: error: Argument 2 to "zip" has incompatible type "list[Hashable | Any] | Hashable | list[Any | tuple[Any, ...]]"; expected "Iterable[Hashable | Any]"  [arg-type]
+ python/pyspark/pandas/groupby.py:3530: error: Argument 2 to "zip" has incompatible type "list[Any | tuple[Any, ...]] | Hashable"; expected "Iterable[Any | tuple[Any, ...]]"  [arg-type]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/csgo/state.py:180: error: Argument "slot" to "Sticker" has incompatible type "int | None"; expected "Literal[0, 1, 2, 3, 4, 5] | None"  [arg-type]

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/concurrency/_asyncio.py:171: error: R? has no attribute "json"  [attr-defined]
+ src/prefect/task_worker.py:387: error: Argument 1 to "submit" of "Executor" has incompatible type "Callable[[Callable[_P, _T], **_P], _T]"; expected "Callable[[Callable[[Task[P, R], UUID | None, TaskRun | None, dict[str, Any] | None, PrefectFuture[Any] | Any | Iterable[PrefectFuture[Any] | Any] | None, Literal['state', 'result'], dict[str, set[RunInput]] | None, dict[str, Any] | None], R | State[Any] | None], Task[[VarArg(Any), KwArg(Any)], Any], UUID, TaskRun, dict[Any, Any], list[Any], str, Any | None], Any | State[Any] | None]"  [arg-type]

operator (https://github.com/canonical/operator)
- ops/pebble.py:1208: error: TypedDict key must be a string literal; expected one of ("command", "service-context", "environment", "user-id", "user", ...)  [literal-required]
- ops/pebble.py:1226: error: TypedDict key must be a string literal; expected one of ("url", "headers")  [literal-required]
+ ops/model.py:820: error: Incompatible types in assignment (expression has type "str", variable has type "Literal['tcp', 'udp', 'icmp']")  [assignment]

pyinstrument (https://github.com/joerick/pyinstrument)
- pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'disabled', 'strict'] | float | bool | None]"; expected "float"  [arg-type]
+ pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'strict'] | float | str | bool | None]"; expected "float"  [arg-type]
- pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'disabled', 'strict'] | float | bool | None]"; expected "Literal['enabled', 'disabled', 'strict']"  [arg-type]
+ pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'strict'] | float | str | bool | None]"; expected "Literal['enabled', 'disabled', 'strict']"  [arg-type]
- pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'disabled', 'strict'] | float | bool | None]"; expected "bool | None"  [arg-type]
+ pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'strict'] | float | str | bool | None]"; expected "bool | None"  [arg-type]

scrapy (https://github.com/scrapy/scrapy)
- tests/test_pipeline_files.py:1058: error: Unused "type: ignore" comment  [unused-ignore]

discord.py (https://github.com/Rapptz/discord.py)
- discord/app_commands/transformers.py:141: error: Incompatible types in assignment (expression has type "list[dict[str, Any]]", target has type "str | int")  [assignment]
+ discord/app_commands/transformers.py:141: error: Incompatible types in assignment (expression has type "list[dict[str, Any]]", target has type "bool | str | int")  [assignment]
- discord/app_commands/transformers.py:143: error: Incompatible types in assignment (expression has type "list[int]", target has type "str | int")  [assignment]
+ discord/app_commands/transformers.py:143: error: Incompatible types in assignment (expression has type "list[int]", target has type "bool | str | int")  [assignment]
- discord/app_commands/transformers.py:151: error: Incompatible types in assignment (expression has type "int | float", target has type "str | int")  [assignment]
+ discord/app_commands/transformers.py:151: error: Incompatible types in assignment (expression has type "int | float", target has type "bool | str | int")  [assignment]
- discord/app_commands/transformers.py:153: error: Incompatible types in assignment (expression has type "int | float", target has type "str | int")  [assignment]
+ discord/app_commands/transformers.py:153: error: Incompatible types in assignment (expression has type "int | float", target has type "bool | str | int")  [assignment]

pandera (https://github.com/pandera-dev/pandera)
+ pandera/backends/ibis/container.py:58: error: Incompatible types in assignment (expression has type "list[tuple[Never, tuple[Any, ...]]]", variable has type "list[tuple[Callable[..., Any], tuple[Any, ...]]]")  [assignment]
+ pandera/backends/ibis/container.py:58: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ pandera/backends/ibis/container.py:58: note: Consider using "Sequence" instead, which is covariant
+ pandera/backends/ibis/container.py:59: error: List item 0 has incompatible type "tuple[Callable[[Any, DataFrameSchema, ColumnInfo], Any], tuple[DataFrameSchema, ColumnInfo]]"; expected "tuple[Never, tuple[Any, ...]]"  [list-item]

rotki (https://github.com/rotki/rotki)
+ rotkehlchen/chain/evm/decoding/balancer/v1/decoder.py:279: error: Dict entry 0 has incompatible type "Literal['balancer-v1', 'balancer-v2', 'balancer-v3', 'beets-v2', 'beets-v3']": "list[tuple[int, Never]]"; expected "str": "list[tuple[int, Callable[..., Any]]]"  [dict-item]
+ rotkehlchen/chain/evm/decoding/balancer/v1/decoder.py:280: error: List item 0 has incompatible type "tuple[int, Callable[[EvmTransaction, list[EvmEvent], list[EvmTxReceiptLog]], list[EvmEvent]]]"; expected "tuple[int, Never]"  [list-item]
+ rotkehlchen/chain/evm/decoding/balancer/v1/decoder.py:281: error: List item 1 has incompatible type "tuple[int, Callable[[EvmTransaction, list[EvmEvent], list[EvmTxReceiptLog]], list[EvmEvent]]]"; expected "tuple[int, Never]"  [list-item]
+ rotkehlchen/chain/evm/decoding/balancer/v2/decoder.py:217: error: Dict entry 0 has incompatible type "Literal['balancer-v1', 'balancer-v2', 'balancer-v3', 'beets-v2', 'beets-v3']": "list[tuple[int, Never]]"; expected "str": "list[tuple[int, Callable[..., Any]]]"  [dict-item]
+ rotkehlchen/chain/evm/decoding/balancer/v2/decoder.py:217: error: List item 0 has incompatible type "tuple[int, Callable[[EvmTransaction, list[EvmEvent], list[EvmTxReceiptLog]], list[EvmEvent]]]"; expected "tuple[int, Never]"  [list-item]
+ rotkehlchen/chain/evm/decoding/quickswap/v3/decoder.py:138: error: Dict entry 0 has incompatible type "Literal['quickswap-v3', 'quickswap-v4']": "list[tuple[int, Never]]"; expected "str": "list[tuple[int, Callable[..., Any]]]"  [dict-item]
+ rotkehlchen/chain/evm/decoding/quickswap/v3/decoder.py:138: error: List item 0 has incompatible type "tuple[int, Callable[[EvmTransaction, list[EvmEvent], list[EvmTxReceiptLog]], list[EvmEvent]]]"; expected "tuple[int, Never]"  [list-item]
+ rotkehlchen/accounting/history_base_entries.py:291: error: Incompatible types in assignment (expression has type "list[tuple[Never, dict[str, Any]]]", variable has type "list[tuple[Callable[..., Any], dict[str, Any]]]")  [assignment]
+ rotkehlchen/accounting/history_base_entries.py:291: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ rotkehlchen/accounting/history_base_entries.py:291: note: Consider using "Sequence" instead, which is covariant
+ rotkehlchen/accounting/history_base_entries.py:292: error: List item 0 has incompatible type "tuple[def add_in_event(self, event_type: AccountingEventType, notes: str, location: LocationIdentifier, timestamp: Timestamp, asset: Asset, amount: FVal, taxable: bool, given_price: Price | None = ..., extra_data: dict[Any, Any] | None = ..., **kwargs: Any) -> None, dict[str, object]]"; expected "tuple[Never, dict[str, Any]]"  [list-item]
+ rotkehlchen/api/services/assets.py:1090: error: List comprehension has incompatible type List[tuple[str, CacheType, Callable[[EvmNodeInquirer, Literal[CacheType.CURVE_LP_TOKENS], MessagesAggregator, bool], list[CurvePoolData] | None], ChainID, EthereumInquirer | OptimismInquirer | ArbitrumOneInquirer | BaseInquirer | GnosisInquirer | PolygonPOSInquirer]]; expected List[tuple[str, CacheType, Never, ChainID, EthereumInquirer | OptimismInquirer | ArbitrumOneInquirer | BaseInquirer | GnosisInquirer | PolygonPOSInquirer]]  [misc]
+ rotkehlchen/api/services/assets.py:1189: error: List comprehension has incompatible type List[tuple[str, CacheType, Callable[[Literal[1, 2, 3], EvmNodeInquirer, MessagesAggregator, str, Literal[CacheType.BALANCER_V1_POOLS, CacheType.BALANCER_V2_POOLS, CacheType.BALANCER_V3_POOLS], bool], tuple[set[ChecksumAddress], set[ChecksumAddress]]], ChainID, GnosisInquirer | EthereumInquirer | ArbitrumOneInquirer]]; expected List[tuple[str, CacheType, Never, ChainID, GnosisInquirer | EthereumInquirer | ArbitrumOneInquirer]]  [misc]
+ rotkehlchen/api/services/assets.py:1204: error: List comprehension has incompatible type List[tuple[str, CacheType, Callable[[Literal[1, 2, 3], EvmNodeInquirer, MessagesAggregator, str, Literal[CacheType.BALANCER_V1_POOLS, CacheType.BALANCER_V2_POOLS, CacheType.BALANCER_V3_POOLS], bool], tuple[set[ChecksumAddress], set[ChecksumAddress]]], ChainID, BaseInquirer | GnosisInquirer | EthereumInquirer | OptimismInquirer | PolygonPOSInquirer | ArbitrumOneInquirer | SonicInquirer]]; expected List[tuple[str, CacheType, Never, ChainID, BaseInquirer | GnosisInquirer | EthereumInquirer | OptimismInquirer | PolygonPOSInquirer | ArbitrumOneInquirer | SonicInquirer]]  [misc]
+ rotkehlchen/api/services/assets.py:1223: error: List comprehension has incompatible type List[tuple[str, CacheType, Callable[[Literal[1, 2, 3], EvmNodeInquirer, MessagesAggregator, str, Literal[CacheType.BALANCER_V1_POOLS, CacheType.BALANCER_V2_POOLS, CacheType.BALANCER_V3_POOLS], bool], tuple[set[ChecksumAddress], set[ChecksumAddress]]], ChainID, BaseInquirer | GnosisInquirer | EthereumInquirer | OptimismInquirer | ArbitrumOneInquirer | SonicInquirer]]; expected List[tuple[str, CacheType, Never, ChainID, BaseInquirer | GnosisInquirer | EthereumInquirer | OptimismInquirer | ArbitrumOneInquirer | SonicInquirer]]  [misc]
+ rotkehlchen/chain/evm/decoding/velodrome/decoder.py:797: error: Dict entry 0 has incompatible type "Literal['velodrome', 'aerodrome']": "list[tuple[int, Never]]"; expected "str": "list[tuple[int, Callable[..., Any]]]"  [dict-item]
+ rotkehlchen/chain/evm/decoding/velodrome/decoder.py:797: error: List item 0 has incompatible type "tuple[int, Callable[[EvmTransaction, list[EvmEvent], list[EvmTxReceiptLog]], list[EvmEvent]]]"; expected "tuple[int, Never]"  [list-item]
+ rotkehlchen/globaldb/asset_updates/parsers.py:112: error: Incompatible types in assignment (expression has type "list[tuple[VersionRange, Never]]", variable has type "list[tuple[VersionRange, Callable[..., Any]]]")  [assignment]
+ rotkehlchen/globaldb/asset_updates/parsers.py:112: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ rotkehlchen/globaldb/asset_updates/parsers.py:112: note: Consider using "Sequence" instead, which is covariant
+ rotkehlchen/globaldb/asset_updates/parsers.py:113: error: List item 0 has incompatible type "tuple[VersionRange, Callable[[DBConnection, str], AssetData]]"; expected "tuple[VersionRange, Never]"  [list-item]
+ rotkehlchen/globaldb/asset_updates/parsers.py:114: error: List item 1 has incompatible type "tuple[VersionRange, Callable[[DBConnection, str], AssetData]]"; expected "tuple[VersionRange, Never]"  [list-item]
+ rotkehlchen/globaldb/asset_updates/parsers.py:115: error: List item 2 has incompatible type "tuple[VersionRange, Callable[[DBConnection, str], AssetData]]"; expected "tuple[VersionRange, Never]"  [list-item]
+ rotkehlchen/globaldb/asset_updates/parsers.py:344: error: Incompatible types in assignment (expression has type "list[tuple[VersionRange, Never]]", variable has type "list[tuple[VersionRange, Callable[..., Any]]]")  [assignment]
+ rotkehlchen/globaldb/asset_updates/parsers.py:344: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ rotkehlchen/globaldb/asset_updates/parsers.py:344: note: Consider using "Sequence" instead, which is covariant
+ rotkehlchen/globaldb/asset_updates/parsers.py:345: error: List item 0 has incompatible type "tuple[VersionRange, Callable[[DBConnection, str], tuple[int, str, str]]]"; expected "tuple[VersionRange, Never]"  [list-item]
+ rotkehlchen/globaldb/asset_updates/parsers.py:346: error: List item 1 has incompatible type "tuple[VersionRange, Callable[[DBConnection, str], tuple[int, str, str, str]]]"; expected "tuple[VersionRange, Never]"  [list-item]
+ rotkehlchen/globaldb/asset_updates/parsers.py:407: error: Incompatible types in assignment (expression has type "list[tuple[VersionRange, Never]]", variable has type "list[tuple[VersionRange, Callable[..., Any]]]")  [assignment]
+ rotkehlchen/globaldb/asset_updates/parsers.py:407: note: "list" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
+ rotkehlchen/globaldb/asset_updates/parsers.py:407: note: Consider using "Sequence" instead, which is covariant
+ rotkehlchen/globaldb/asset_updates/parsers.py:408: error: List item 0 has incompatible type "tuple[VersionRange, Callable[[DBConnection, str], tuple[int, str]]]"; expected "tuple[VersionRange, Never]"  [list-item]

dedupe (https://github.com/dedupeio/dedupe)
- dedupe/api.py:1547: error: Redundant cast to "Literal['match', 'distinct']"  [redundant-cast]

pytest (https://github.com/pytest-dev/pytest)
+ testing/test_assertrewrite.py:963: error: Unused "type: ignore" comment  [unused-ignore]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/groupby/groupby.py:1607: error: Unused "type: ignore" comment  [unused-ignore]

materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/cli/scratch/__main__.py:95: error: Argument 1 to "join" of "str" has incompatible type "list[str | Callable[[Any], Any] | Callable[[], None] | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]]"; expected "Iterable[str]"  [arg-type]
+ misc/python/materialize/cli/scratch/__main__.py:95: error: Argument 1 to "join" of "str" has incompatible type "list[Callable[[Any], Any] | Callable[[], None] | str | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]]"; expected "Iterable[str]"  [arg-type]
- misc/python/materialize/cli/scratch/__main__.py:101: error: Argument 1 to "add_parser" of "_SubParsersAction" has incompatible type "str | Callable[[Any], Any] | Callable[[], None] | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]"; expected "str"  [arg-type]
+ misc/python/materialize/cli/scratch/__main__.py:101: error: Argument 1 to "add_parser" of "_SubParsersAction" has incompatible type "Callable[[Any], Any] | Callable[[], None] | str | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]"; expected "str"  [arg-type]
- misc/python/materialize/cli/scratch/__main__.py:101: error: Argument "aliases" to "add_parser" of "_SubParsersAction" has incompatible type "str | Callable[[Any], Any] | Callable[[], None] | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]"; expected "Iterable[str]"  [arg-type]
+ misc/python/materialize/cli/scratch/__main__.py:101: error: Argument "aliases" to "add_parser" of "_SubParsersAction" has incompatible type "Callable[[Any], Any] | Callable[[], None] | str | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]"; expected "Iterable[str]"  [arg-type]
- misc/python/materialize/cli/scratch/__main__.py:101: error: Argument "description" to "add_parser" of "_SubParsersAction" has incompatible type "str | Callable[[Any], Any] | Callable[[], None] | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]"; expected "str | None"  [arg-type]
+ misc/python/materialize/cli/scratch/__main__.py:101: error: Argument "description" to "add_parser" of "_SubParsersAction" has incompatible type "Callable[[Any], Any] | Callable[[], None] | str | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]"; expected "str | None"  [arg-type]
- misc/python/materialize/cli/scratch/__main__.py:101: error: Argument "help" to "add_parser" of "_SubParsersAction" has incompatible type "str | Callable[[Any], Any] | Callable[[], None] | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]"; expected "str | None"  [arg-type]
+ misc/python/materialize/cli/scratch/__main__.py:101: error: Argument "help" to "add_parser" of "_SubParsersAction" has incompatible type "Callable[[Any], Any] | Callable[[], None] | str | Callable[[ArgumentParser], None] | Callable[[Namespace], None] | list[str]"; expected "str | None"  [arg-type]
- misc/python/materialize/cli/scratch/__main__.py:103: error: Argument 1 to "run" has incompatible type "ArgumentParser"; expected "Namespace"  [arg-type]
+ misc/python/materialize/cli/scratch/__main__.py:103: error: Argument 1 has incompatible type "ArgumentParser"; expected "Namespace"  [arg-type]

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/net/server_spec.py:85: error: Unused "type: ignore" comment  [unused-ignore]
- mitmproxy/flowfilter.py:58: error: Redundant cast to "RegexFlag"  [redundant-cast]

jax (https://github.com/google/jax)
- jax/_src/pallas/mosaic/lowering.py:737: error: Redundant cast to "Literal['parallel', 'core_parallel', 'subcore_parallel', 'arbitrary']"  [redundant-cast]
- jax/_src/pallas/mosaic/lowering.py:914: error: Argument 1 to "_get_dimension_semantics" has incompatible type "tuple[Literal['parallel', 'core_parallel', 'subcore_parallel', 'arbitrary'] | GridDimensionSemantics, ...]"; expected "Sequence[str]"  [arg-type]
+ jax/_src/pallas/mosaic/lowering.py:914: error: Argument 1 to "_get_dimension_semantics" has incompatible type "tuple[Literal['core_parallel', 'subcore_parallel', 'arbitrary'] | GridDimensionSemantics | str, ...]"; expected "Sequence[str]"  [arg-type]
- jax/_src/internal_test_util/test_harnesses.py:2236: error: Incompatible types in assignment (expression has type "tuple[ndarray[tuple[Any, ...], dtype[unsignedinteger[_8Bit]]] | ndarray[tuple[Any, ...], dtype[unsignedinteger[_32Bit]]] | int, ...]", variable has type "list[list[int]]")  [assignment]
- jax/_src/internal_test_util/test_harnesses.py:2236: error: Incompatible types in assignment (expression has type "tuple[ndarray[tuple[Any, ...], dtype[unsignedinteger[_8Bit]]] | ndarray[tuple[Any, ...], dtype[unsignedinteger[_32Bit]]] | int, ...]", variable has type "tuple[int, ...]")  [assignment]
+ jax/_src/internal_test_util/test_harnesses.py:2236: error: Incompatible types in assignment (expression has type "tuple[object, ...]", variable has type "list[list[int]]")  [assignment]
+ jax/_src/internal_test_util/test_harnesses.py:2236: error: Incompatible types in assignment (expression has type "tuple[object, ...]", variable has type "tuple[int, ...]")  [assignment]
- jax/_src/internal_test_util/test_harnesses.py:2295: error: Incompatible types in assignment (expression has type "tuple[ndarray[tuple[Any, ...], dtype[unsignedinteger[_8Bit]]] | ndarray[tuple[Any, ...], dtype[unsignedinteger[_32Bit]]] | int, ...]", variable has type "list[list[int]]")  [assignment]
+ jax/_src/internal_test_util/test_harnesses.py:2295: error: Incompatible types in assignment (expression has type "tuple[int | ndarray[tuple[Any, ...], dtype[unsignedinteger[_8Bit]]] | ndarray[tuple[Any, ...], dtype[unsignedinteger[_32Bit]]], ...]", variable has type "list[list[int]]")  [assignment]

packaging (https://github.com/pypa/packaging)
+ src/packaging/version.py:293: error: Unused "type: ignore" comment  [unused-ignore]

git-revise (https://github.com/mystor/git-revise)
- gitrevise/odb.py:413: error: Redundant cast to "bytes"  [redundant-cast]

meson (https://github.com/mesonbuild/meson)
+ mesonbuild/interpreter/interpreter.py:421:13: error: Dict entry 0 has incompatible type "type[list[Any]]": "type[ArrayHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:422:13: error: Dict entry 1 has incompatible type "type[dict[Any, Any]]": "type[DictHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:423:13: error: Dict entry 2 has incompatible type "type[int]": "type[IntegerHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:424:13: error: Dict entry 3 has incompatible type "type[bool]": "type[BooleanHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:425:13: error: Dict entry 4 has incompatible type "type[str]": "type[StringHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:426:13: error: Dict entry 5 has incompatible type "type[MesonVersionString]": "type[MesonVersionStringHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:427:13: error: Dict entry 6 has incompatible type "type[DependencyVariableString]": "type[DependencyVariableStringHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:428:13: error: Dict entry 7 has incompatible type "type[OptionString]": "type[OptionStringHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:431:13: error: Dict entry 8 has incompatible type "type[File]": "type[FileHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:432:13: error: Dict entry 9 has incompatible type "type[SharedLibrary]": "type[SharedLibraryHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:433:13: error: Dict entry 10 has incompatible type "type[StaticLibrary]": "type[StaticLibraryHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:434:13: error: Dict entry 11 has incompatible type "type[BothLibraries]": "type[BothLibrariesHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:435:13: error: Dict entry 12 has incompatible type "type[SharedModule]": "type[SharedModuleHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:436:13: error: Dict entry 13 has incompatible type "type[Executable]": "type[ExecutableHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:437:13: error: Dict entry 14 has incompatible type "type[Jar]": "type[JarHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:438:13: error: Dict entry 15 has incompatible type "type[CustomTarget]": "type[CustomTargetHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:439:13: error: Dict entry 16 has incompatible type "type[CustomTargetIndex]": "type[CustomTargetIndexHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:440:13: error: Dict entry 17 has incompatible type "type[Generator]": "type[GeneratorHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:441:13: error: Dict entry 18 has incompatible type "type[GeneratedList]": "type[GeneratedListHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:442:13: error: Dict entry 19 has incompatible type "type[ExtractedObjects]": "type[GeneratedObjectsHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:443:13: error: Dict entry 20 has incompatible type "type[RunTarget]": "type[RunTargetHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:444:13: error: Dict entry 21 has incompatible type "type[AliasTarget]": "type[AliasTargetHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:445:13: error: Dict entry 22 has incompatible type "type[Headers]": "type[HeadersHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:446:13: error: Dict entry 23 has incompatible type "type[Man]": "type[ManHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:447:13: error: Dict entry 24 has incompatible type "type[EmptyDir]": "type[EmptyDirHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:448:13: error: Dict entry 25 has incompatible type "type[Data]": "type[DataHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:449:13: error: Dict entry 26 has incompatible type "type[SymlinkData]": "type[SymlinkDataHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:450:13: error: Dict entry 27 has incompatible type "type[InstallDir]": "type[InstallDirHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:451:13: error: Dict entry 28 has incompatible type "type[IncludeDirs]": "type[IncludeDirsHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:452:13: error: Dict entry 29 has incompatible type "type[EnvironmentVariables]": "type[EnvironmentVariablesHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:453:13: error: Dict entry 30 has incompatible type "type[StructuredSources]": "type[StructuredSourcesHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:454:13: error: Dict entry 31 has incompatible type "type[RunResult]": "type[TryRunResultHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:455:13: error: Dict entry 32 has incompatible type "type[ExternalLibrary]": "type[ExternalLibraryHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:456:13: error: Dict entry 33 has incompatible type "type[Feature]": "type[FeatureOptionHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:457:13: error: Dict entry 34 has incompatible type "type[MachineInfo]": "type[MachineHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:458:13: error: Dict entry 35 has incompatible type "type[ConfigurationData]": "type[ConfigurationDataHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:471:13: error: Dict entry 0 has incompatible type "type[Dependency]": "type[DependencyHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:472:13: error: Dict entry 1 has incompatible type "type[Program]": "type[ProgramHolder[_PROG]]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:473:13: error: Dict entry 2 has incompatible type "type[Compiler]": "type[CompilerHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:474:13: error: Dict entry 3 has incompatible type "type[ModuleObject]": "type[ModuleObjectHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:475:13: error: Dict entry 4 has incompatible type "type[MutableModuleObject]": "type[MutableModuleObjectHolder]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
+ mesonbuild/interpreter/interpreter.py:486:13: error: Dict entry 0 has incompatible type "type[HoldableObject]": "type[ObjectHolder[Any]]"; expected "type[HoldableObject] | type[int] | type[str] | type[list[Any]] | type[dict[Any, Any]]": "None"  [dict-item]
- mesonbuild/modules/rust.py:928:60: error: Redundant cast to "Literal['c', 'cpp', 'cuda', 'fortran', 'd', 'objc', 'objcpp', 'rust', 'vala', 'cs', 'swift', 'java', 'cython', 'nasm', 'masm', 'linearasm']"  [redundant-cast]

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/ext/autodoc/_directive_options.py:225: error: Unused "type: ignore" comment  [unused-ignore]
+ sphinx/ext/autodoc/_directive_options.py:232: error: Unused "type: ignore" comment  [unused-ignore]

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ bson/__init__.py:1363: error: Cannot infer value of type parameter "_DocumentType" of "_bson_to_dict"  [misc]

paasta (https://github.com/yelp/paasta)
+ paasta_tools/metrics/metastatus_lib.py:956: error: List item 0 has incompatible type "Callable[[KubeClient, str], HealthCheckResult]"; expected "None"  [list-item]
+ paasta_tools/metrics/metastatus_lib.py:956: error: List item 1 has incompatible type "Callable[[KubeClient, str], HealthCheckResult]"; expected "None"  [list-item]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

1 more reviewer
@davidhalter davidhalter davidhalter left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

upnext

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Regression: false positive avoid redundant cast with literal union Type Narrowing: if val == Literal should always narrow to Literal Narrowing types to Literal using in syntax Literal typeguard TypedDict item insertion support
meet_types gives unexpected results when meeting literal and Instance Specify behavior for Literal? types. mypy cannot decide if a cast is necessary or redundant

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@randolf-scholz @davidhalter @hauntsaninja
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.