Skip to content

[pyrefly] Preserve literal keys in dict unions - #4388

Open
lyydsheep wants to merge 1 commit into
facebook:mainfrom
lyydsheep:codex/issue-4380-dict-union-literal-keys
Open

[pyrefly] Preserve literal keys in dict unions#4388
lyydsheep wants to merge 1 commit into
facebook:mainfrom
lyydsheep:codex/issue-4380-dict-union-literal-keys

Conversation

@lyydsheep

Copy link
Copy Markdown

Fixes #4380

When a built-in dict is merged with a dict-literal RHS using | or |=, Pyrefly now applies a soft contextual hint from the lhs while inferring the literal. Compatible Literal keys remain precise without changing ordinary dict inference or other operators; incompatible keys and values still report assignment errors.

Validation:

  • cargo test -p pyrefly test::operators
  • python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema

The local .scratch planning files are intentionally not part of this PR.

@meta-cla meta-cla Bot added the cla signed label Aug 1, 2026
@github-actions github-actions Bot added the size/s label Aug 1, 2026
@meta-codesync

meta-codesync Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D114457106. (Because this pull request was imported automatically, there will not be any future comments.)

@lyydsheep
lyydsheep marked this pull request as ready for review August 2, 2026 04:14
@github-actions
github-actions Bot requested a review from rchen152 August 2, 2026 09:44
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

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

rotki (https://github.com/rotki/rotki)
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `and_op` with type `bool` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `limit` with type `int | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `offset` with type `int | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `from_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `to_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `assets` with type `tuple[Asset, ...] | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `location` with type `Location | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `entry_types` with type `IncludeExcludeFilterData | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `exclude_ignored_assets` with type `bool` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `notes_substring` with type `str | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `min_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:802:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `max_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.EvmEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `and_op` with type `bool` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `limit` with type `int | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `offset` with type `int | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `from_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `to_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `assets` with type `tuple[Asset, ...] | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `location` with type `Location | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `entry_types` with type `IncludeExcludeFilterData | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `exclude_ignored_assets` with type `bool` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `notes_substring` with type `str | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `min_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:813:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `max_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.SolanaEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `and_op` with type `bool` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `limit` with type `int | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `offset` with type `int | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `from_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `to_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `assets` with type `tuple[Asset, ...] | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `location` with type `Location | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `entry_types` with type `IncludeExcludeFilterData | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `exclude_ignored_assets` with type `bool` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `notes_substring` with type `str | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `min_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:826:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `max_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.HistoryEventWithCounterpartyFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `and_op` with type `bool` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `limit` with type `int | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `offset` with type `int | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `from_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `to_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `assets` with type `tuple[Asset, ...] | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `location` with type `Location | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `entry_types` with type `IncludeExcludeFilterData | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `exclude_ignored_assets` with type `bool` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `notes_substring` with type `str | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `min_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:831:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `max_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.HistoryEventWithTxRefFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `and_op` with type `bool` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `limit` with type `int | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `offset` with type `int | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `from_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `to_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `assets` with type `tuple[Asset, ...] | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `location` with type `Location | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `entry_types` with type `IncludeExcludeFilterData | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `exclude_ignored_assets` with type `bool` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `notes_substring` with type `str | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `min_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:835:17-35: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `max_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.EthStakingEventFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `and_op` with type `bool` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `limit` with type `int | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `offset` with type `int | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `from_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `to_ts` with type `Timestamp | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `assets` with type `tuple[Asset, ...] | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `location` with type `Location | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `entry_types` with type `IncludeExcludeFilterData | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `exclude_ignored_assets` with type `bool` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `notes_substring` with type `str | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `min_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/api/v1/schemas.py:839:57-75: Unpacked keyword argument `list[Any] | Any | None` is not assignable to parameter `max_amount` with type `FVal | None` in function `rotkehlchen.db.filtering.HistoryBaseEntryFilterQuery.make` [bad-argument-type]
- ERROR rotkehlchen/assets/asset.py:518:13-37: Result of call expression is of type `str | Any | None` and is not used; assign to `_` if this is intentional [unused-call-result]

pytest (https://github.com/pytest-dev/pytest)
- ERROR src/_pytest/config/argparsing.py:61:41-66:2: `dict[type[bool] | type[float] | type[int] | type[str] | Any, str | Any]` is not assignable to `dict[object, _IniTypeTag]` [bad-assignment]

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dict union with literal keys widens to str.

2 participants