Skip to content

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented Oct 31, 2025

Summary

Discussion with @ibraheemdev clarified that #21168 was incorrect. In a case of failed inference of a dict literal as a TypedDict, we should store the context-less inferred type of the dict literal as the type of the dict literal expression itself; the fallback to declared type should happen at the level of the overall assignment definition.

The reason the latter isn't working yet is because currently we (wrongly) consider a homogeneous dict type as assignable to a TypedDict, so we don't actually consider the assignment itself as failed. So the "bug" I observed (and tried to fix) will naturally be fixed by implementing TypedDict assignability rules.

Rollback #21168 except for the tests, and modify the tests to include TODOs as needed.

Test Plan

Updated mdtests.

@carljm carljm added ty Multi-file analysis & type inference internal An internal refactor or improvement labels Oct 31, 2025
@carljm carljm requested a review from ibraheemdev October 31, 2025 15:51
@github-actions
Copy link
Contributor

Diagnostic diff on typing conformance tests

Changes were detected when running ty on typing conformance tests
--- old-output.txt	2025-10-31 15:52:43.080086460 +0000
+++ new-output.txt	2025-10-31 15:52:46.243119858 +0000
@@ -927,7 +927,6 @@
 typeddicts_operations.py:29:42: error[invalid-argument-type] Invalid argument to key "year" with declared type `int` on TypedDict `Movie`: value of type `float`
 typeddicts_operations.py:32:36: error[invalid-key] Invalid key for TypedDict `Movie`: Unknown key "other"
 typeddicts_operations.py:37:20: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
-typeddicts_operations.py:47:1: error[unresolved-attribute] Object of type `Movie` has no attribute `clear`
 typeddicts_operations.py:62:1: error[unresolved-attribute] Object of type `MovieOptional` has no attribute `clear`
 typeddicts_readonly.py:24:4: error[invalid-assignment] Cannot assign to key "members" on TypedDict `Band`: key is marked read-only
 typeddicts_readonly.py:50:4: error[invalid-assignment] Cannot assign to key "title" on TypedDict `Movie1`: key is marked read-only
@@ -947,5 +946,5 @@
 typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
 typeddicts_usage.py:28:18: error[invalid-key] Invalid key for TypedDict `Movie`: Unknown key "title"
 typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions. Did you mean to use a concrete TypedDict or `collections.abc.Mapping[str, object]` instead?
-Found 949 diagnostics
+Found 948 diagnostics
 WARN A fatal error occurred while checking some files. Not all project files were analyzed. See the diagnostics list above for details.

@AlexWaygood AlexWaygood removed their request for review October 31, 2025 15:53
@github-actions
Copy link
Contributor

mypy_primer results

Changes were detected when running on open source projects
cloud-init (https://github.com/canonical/cloud-init)
- cloudinit/net/ephemeral.py:140:13: warning[possibly-missing-attribute] Attribute `get` may be missing on object of type `str | Unknown`
- cloudinit/net/ephemeral.py:140:36: error[not-iterable] Object of type `Interface | None` may not be iterable
+ cloudinit/net/ephemeral.py:140:13: error[unresolved-attribute] Object of type `str` has no attribute `get`
- Found 1140 diagnostics
+ Found 1139 diagnostics
No memory usage changes detected ✅

Copy link
Member

@ibraheemdev ibraheemdev left a comment

Choose a reason for hiding this comment

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

Thanks!

@carljm carljm merged commit 9664474 into main Oct 31, 2025
42 checks passed
@carljm carljm deleted the cjm/rollback branch October 31, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants