File tree Expand file tree Collapse file tree
crates/ty_python_semantic Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2513,6 +2513,9 @@ from typing_extensions import TypedDict
25132513# error: [invalid-argument-type] "Invalid argument to parameter `typename` of `TypedDict()`"
25142514Bad1 = TypedDict(123 , {" name" : str })
25152515
2516+ # error: [invalid-argument-type] "The name of a `TypedDict` (`WrongName`) must match the name of the variable it is assigned to (`BadTypedDict3`)"
2517+ BadTypedDict3 = TypedDict(" WrongName" , {" name" : str })
2518+
25162519# error: [invalid-argument-type] "Expected a dict literal for parameter `fields` of `TypedDict()`"
25172520Bad2 = TypedDict(" Bad2" , " not a dict" )
25182521
Original file line number Diff line number Diff line change @@ -159,7 +159,19 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
159159 }
160160
161161 let name = if let Some ( literal) = name_type. as_string_literal ( ) {
162- Name :: new ( literal. value ( db) )
162+ let name = literal. value ( db) . to_string ( ) ;
163+
164+ if let Some ( assigned_name) = definition. and_then ( |definition| definition. name ( db) )
165+ && name != assigned_name
166+ && let Some ( builder) = self . context . report_lint ( & INVALID_ARGUMENT_TYPE , name_arg)
167+ {
168+ builder. into_diagnostic ( format_args ! (
169+ "The name of a `TypedDict` (`{name}`) must match \
170+ the name of the variable it is assigned to (`{assigned_name}`)"
171+ ) ) ;
172+ }
173+
174+ Name :: new ( name)
163175 } else {
164176 if !name_type. is_assignable_to ( db, KnownClass :: Str . to_instance ( db) )
165177 && let Some ( builder) = self . context . report_lint ( & INVALID_ARGUMENT_TYPE , name_arg)
You can’t perform that action at this time.
0 commit comments