Skip to content

Commit 044240c

Browse files
committed
Remove as_anonymous method entirely to avoid future bugs
1 parent 1dc6f2c commit 044240c

4 files changed

Lines changed: 6 additions & 10 deletions

File tree

mypy/constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ def visit_instance(self, template: Instance) -> list[Constraint]:
816816
if isinstance(actual, Overloaded) and actual.fallback is not None:
817817
actual = actual.fallback
818818
if isinstance(actual, TypedDictType):
819-
actual = actual.as_anonymous().fallback
819+
actual = actual.create_anonymous_fallback()
820820
if isinstance(actual, LiteralType):
821821
actual = actual.fallback
822822
if isinstance(actual, Instance):

mypy/meet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ def typed_dict_mapping_overlap(
12631263
key_type, value_type = get_proper_types(other.args)
12641264

12651265
# TODO: is there a cleaner way to get str_type here?
1266-
fallback = typed.as_anonymous().fallback
1266+
fallback = typed.create_anonymous_fallback()
12671267
str_type = fallback.type.bases[0].args[0] # typing._TypedDict inherits Mapping[str, object]
12681268

12691269
# Special case: a TypedDict with no required keys overlaps with an empty dict.

mypy/plugins/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def typed_dict_update_signature_callback(ctx: MethodSigContext) -> CallableType:
480480
if not isinstance(arg_type, TypedDictType):
481481
return signature
482482
arg_type = ctx.type.copy_modified(
483-
fallback=arg_type.as_anonymous().fallback, required_keys=set()
483+
fallback=arg_type.create_anonymous_fallback(), required_keys=set()
484484
)
485485
if ctx.args and ctx.args[0]:
486486
if signature.name in _TP_DICT_MUTATING_METHODS:

mypy/types.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,11 +3080,11 @@ def is_final(self) -> bool:
30803080
def is_anonymous(self) -> bool:
30813081
return self.fallback.type.fullname in TPDICT_FB_NAMES
30823082

3083-
def as_anonymous(self) -> TypedDictType:
3083+
def create_anonymous_fallback(self) -> Instance:
30843084
if self.is_anonymous():
3085-
return self
3085+
return self.fallback
30863086
assert self.fallback.type.typeddict_type is not None
3087-
return self.fallback.type.typeddict_type.as_anonymous()
3087+
return self.fallback.type.typeddict_type.create_anonymous_fallback()
30883088

30893089
def copy_modified(
30903090
self,
@@ -3110,10 +3110,6 @@ def copy_modified(
31103110
required_keys &= set(item_names)
31113111
return TypedDictType(items, required_keys, readonly_keys, fallback, self.line, self.column)
31123112

3113-
def create_anonymous_fallback(self) -> Instance:
3114-
anonymous = self.as_anonymous()
3115-
return anonymous.fallback
3116-
31173113
def names_are_wider_than(self, other: TypedDictType) -> bool:
31183114
return len(other.items.keys() - self.items.keys()) == 0
31193115

0 commit comments

Comments
 (0)