Skip to content

Commit

Permalink
dataclass.replace: allow transformed classes (#15915)
Browse files Browse the repository at this point in the history
We [already
synthesize](#15843 (comment))
`__dataclass_fields__` for all classes including
`@dataclass_transform`'d ones, thus assume more than PEP-681 says. We
might as well assume `dataclasses.replace` applies on all same classes.
This way we risk false positive since it'll raise in runtime.

Fixes #15843.
  • Loading branch information
ikonst authored Sep 17, 2023
1 parent 0222bf4 commit b65cd9a
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ def transform(self) -> bool:
add_attribute_to_class(self._api, self._cls, "__match_args__", match_args_type)

self._add_dataclass_fields_magic_attribute()

if self._spec is _TRANSFORM_SPEC_FOR_DATACLASSES:
self._add_internal_replace_method(attributes)
self._add_internal_replace_method(attributes)
if "__post_init__" in info.names:
self._add_internal_post_init_method(attributes)

Expand Down

0 comments on commit b65cd9a

Please sign in to comment.