From d54ef84f40ae6be531f36d8fdef69a76493db002 Mon Sep 17 00:00:00 2001 From: Ilya Priven Date: Sat, 19 Aug 2023 23:11:44 -0400 Subject: [PATCH] dataclass.replace: allow transformed classes --- mypy/plugins/dataclasses.py | 4 +--- test-data/unit/check-dataclass-transform.test | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mypy/plugins/dataclasses.py b/mypy/plugins/dataclasses.py index d782acf50af5..a30a7ba9e125 100644 --- a/mypy/plugins/dataclasses.py +++ b/mypy/plugins/dataclasses.py @@ -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) diff --git a/test-data/unit/check-dataclass-transform.test b/test-data/unit/check-dataclass-transform.test index 9029582ece82..58cd5e5a90f8 100644 --- a/test-data/unit/check-dataclass-transform.test +++ b/test-data/unit/check-dataclass-transform.test @@ -853,7 +853,7 @@ class Person: name: str p = Person('John') -y = replace(p, name='Bob') # E: Argument 1 to "replace" has incompatible type "Person"; expected a dataclass +y = replace(p, name='Bob') [typing fixtures/typing-full.pyi] [builtins fixtures/dataclasses.pyi]