Skip to content

[ty] Support ** unpacking of TypedDict in dict-literal assignments#24703

Merged
charliermarsh merged 1 commit intomainfrom
charlie/unpack-literal
Apr 22, 2026
Merged

[ty] Support ** unpacking of TypedDict in dict-literal assignments#24703
charliermarsh merged 1 commit intomainfrom
charlie/unpack-literal

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

Summary

We already support ** unpacking of TypedDict in named TypedDict constructors; this PR extends it to literals annotated as TypedDict, as in:

from typing import TypedDict

class MyTypedDict1(TypedDict):
    aaa: int
    bbb: int

class MyTypedDict2(TypedDict):
    aaa: int
    bbb: int
    ccc: int

d1: MyTypedDict1 = {
    "aaa": 1,
    "bbb": 2,
}

d2: MyTypedDict2 = {
    **d1,
    "ccc": 3,
}

Closes astral-sh/ty#1493

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Apr 17, 2026
@charliermarsh charliermarsh changed the title [ty] Support **TypedDict unpacking in dict-literal assignments [ty] Support ** unpacking of TypedDict in dict-literal assignments Apr 17, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 17, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.36%. The number of fully passing files held steady at 79/133.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 17, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 17, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
missing-typed-dict-key 0 37 0
invalid-return-type 0 5 0
Total 0 42 0
Raw diff (42 changes)
core (https://github.com/home-assistant/core)
- homeassistant/components/energy/data.py:786:20 error[missing-typed-dict-key] Missing required key 'stat_energy_from' in TypedDict `BatterySourceType` constructor
- homeassistant/components/energy/data.py:786:20 error[missing-typed-dict-key] Missing required key 'stat_energy_to' in TypedDict `BatterySourceType` constructor
- homeassistant/components/energy/data.py:786:20 error[missing-typed-dict-key] Missing required key 'type' in TypedDict `BatterySourceType` constructor
- homeassistant/components/energy/data.py:786:20 error[invalid-return-type] Return type does not match returned value: expected `BatterySourceType`, found `dict[str, Unknown | str]`
- homeassistant/components/energy/data.py:789:16 error[missing-typed-dict-key] Missing required key 'stat_energy_from' in TypedDict `BatterySourceType` constructor
- homeassistant/components/energy/data.py:789:16 error[missing-typed-dict-key] Missing required key 'stat_energy_to' in TypedDict `BatterySourceType` constructor
- homeassistant/components/energy/data.py:789:16 error[missing-typed-dict-key] Missing required key 'type' in TypedDict `BatterySourceType` constructor
- homeassistant/components/energy/data.py:789:16 error[invalid-return-type] Return type does not match returned value: expected `BatterySourceType`, found `dict[str, Unknown | str]`
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'cost_adjustment_day' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'entity_energy_price' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'entity_energy_price_export' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'number_energy_price' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'number_energy_price_export' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'stat_compensation' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'stat_cost' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'stat_energy_from' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'stat_energy_to' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[missing-typed-dict-key] Missing required key 'type' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:804:20 error[invalid-return-type] Return type does not match returned value: expected `GridSourceType`, found `dict[str, Unknown | str]`
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'cost_adjustment_day' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'entity_energy_price' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'entity_energy_price_export' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'number_energy_price' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'number_energy_price_export' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'stat_compensation' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'stat_cost' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'stat_energy_from' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'stat_energy_to' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[missing-typed-dict-key] Missing required key 'type' in TypedDict `GridSourceType` constructor
- homeassistant/components/energy/data.py:807:16 error[invalid-return-type] Return type does not match returned value: expected `GridSourceType`, found `dict[str, Unknown | str]`

pyjwt (https://github.com/jpadilla/pyjwt)
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'enforce_minimum_key_length' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'require' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'strict_aud' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'verify_aud' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'verify_exp' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'verify_iat' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'verify_iss' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'verify_jti' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'verify_nbf' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'verify_signature' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[missing-typed-dict-key] Missing required key 'verify_sub' in TypedDict `FullOptions` constructor
- jwt/api_jwt.py:88:16 error[invalid-return-type] Return type does not match returned value: expected `FullOptions`, found `dict[str, Unknown]`

Full report with detailed diff (timing results)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 17, 2026

Merging this PR will degrade performance by 4.59%

❌ 1 regressed benchmark
✅ 46 untouched benchmarks
⏩ 60 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime pydantic 7.8 s 8.1 s -4.59%

Comparing charlie/unpack-literal (10f4c9a) with main (67296f0)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@charliermarsh charliermarsh marked this pull request as ready for review April 18, 2026 03:03
@charliermarsh charliermarsh marked this pull request as draft April 18, 2026 19:13
@charliermarsh charliermarsh marked this pull request as ready for review April 18, 2026 23:55
@charliermarsh charliermarsh force-pushed the charlie/unpack-literal branch from 7b49ce5 to 10f4c9a Compare April 19, 2026 00:36
@carljm carljm removed their request for review April 19, 2026 04:11
Copy link
Copy Markdown
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you

@charliermarsh charliermarsh merged commit ae613c5 into main Apr 22, 2026
55 of 56 checks passed
@charliermarsh charliermarsh deleted the charlie/unpack-literal branch April 22, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unpacking a typed dictionary into another should transfer defined keys.

2 participants