Skip to content

[ty] Avoid eager TypedDict diagnostics in TypedDict | dict unions#24151

Merged
charliermarsh merged 1 commit intomainfrom
charlie/typed-dict-dict-union-narrowing
Mar 24, 2026
Merged

[ty] Avoid eager TypedDict diagnostics in TypedDict | dict unions#24151
charliermarsh merged 1 commit intomainfrom
charlie/typed-dict-dict-union-narrowing

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Mar 24, 2026

Summary

When a dict literal was inferred against a union containing both a TypedDict and a plain dict, we were validating too eagerly against the TypedDict arm and emitting false-positives (like missing-typed-dict-key).

@astral-sh-bot astral-sh-bot bot added the ty Multi-file analysis & type inference label Mar 24, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 24, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 85.38%. The percentage of expected errors that received a diagnostic held steady at 78.70%. The number of fully passing files held steady at 64/132.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 24, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 24, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-key 0 3 0
missing-typed-dict-key 0 2 0
invalid-argument-type 0 1 0
Total 0 6 0

Raw diff:

alerta (https://github.com/alerta/alerta)
- alerta/utils/logging.py:68:33 error[missing-typed-dict-key] Missing required key 'name' in TypedDict `_FilterConfigurationTypedDict` constructor
- alerta/utils/logging.py:69:25 error[invalid-key] Unknown key "()" for TypedDict `_FilterConfigurationTypedDict`
- alerta/utils/logging.py:70:25 error[invalid-key] Unknown key "methods" for TypedDict `_FilterConfigurationTypedDict`
- alerta/utils/logging.py:72:32 error[missing-typed-dict-key] Missing required key 'name' in TypedDict `_FilterConfigurationTypedDict` constructor
- alerta/utils/logging.py:73:25 error[invalid-key] Unknown key "()" for TypedDict `_FilterConfigurationTypedDict`

rotki (https://github.com/rotki/rotki)
- rotkehlchen/logging.py:209:20 error[invalid-argument-type] Invalid argument to key "filters" with declared type `dict[str, _FilterConfigurationTypedDict | dict[str, Any]]` on TypedDict `_DictConfigArgs`: value of type `dict[str, dict[str, <class 'PywsgiFilter'>]]`

Full report with detailed diff (timing results)

@charliermarsh
Copy link
Copy Markdown
Member Author

I believe those were all false positives.

@charliermarsh charliermarsh force-pushed the charlie/typed-dict-dict-union-narrowing branch from 82a5ed8 to 05306a6 Compare March 24, 2026 02:05
@charliermarsh charliermarsh marked this pull request as ready for review March 24, 2026 02:12
@charliermarsh charliermarsh merged commit e7f1c53 into main Mar 24, 2026
49 checks passed
@charliermarsh charliermarsh deleted the charlie/typed-dict-dict-union-narrowing branch March 24, 2026 18:35
carljm added a commit that referenced this pull request Mar 25, 2026
* main:
  [ty] Avoid eager TypedDict diagnostics in `TypedDict | dict` unions (#24151)
  `F507`: Fix false negative for non-tuple RHS in `%`-formatting (#24142)
  [ty] Update `SpecializationBuilder` hook to get both lower/upper bounds (#23848)
  Fix `%foo?` parsing in IPython assignment expressions (#24152)
  `E501`/`W505`/formatter: Exclude nested pragma comments from line width calculation  (#24071)
  [ty] Fix Salsa panic propagation (#24141)
  [ty] Support `type:ignore[ty:code]` suppressions (#24096)
  [ty] Support narrowing for extended walrus targets (#24129)
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.

2 participants