Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add any attribute to type
  • Loading branch information
cdce8p committed Aug 25, 2025
commit c5e74f998175cd7a567328ebd31c710a5d2d8ba0
4 changes: 4 additions & 0 deletions mypy/checker_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ def checking_await_set(self) -> Iterator[None]:
def get_precise_awaitable_type(self, typ: Type, local_errors: ErrorWatcher) -> Type | None:
raise NotImplementedError

@abstractmethod
def add_any_attribute_to_type(self, typ: Type, name: str) -> Type:
raise NotImplementedError

@abstractmethod
def is_defined_in_stub(self, typ: Instance, /) -> bool:
raise NotImplementedError
Expand Down
2 changes: 2 additions & 0 deletions mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ def visit_class_pattern(self, o: ClassPattern) -> PatternType:
),
pattern,
)
elif keyword is not None:
new_type = self.chk.add_any_attribute_to_type(new_type, keyword)

inner_type, inner_rest_type, inner_captures = self.accept(pattern, key_type)
if is_uninhabited(inner_type):
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/check-python310.test
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ match n:
# Matching against object should not emit an error for non-existing keys
case object(a=k):
reveal_type(n) # N: Revealed type is "builtins.object"
reveal_type(n.a) # N: Revealed type is "Any"
reveal_type(k) # N: Revealed type is "Any"

[case testMatchClassPatternDuplicateKeyword]
Expand Down
Loading