From f4179e5c5a182dd265b349c521dc415e46071f35 Mon Sep 17 00:00:00 2001 From: Wesley Collin Wright Date: Tue, 7 Feb 2023 17:26:09 +0000 Subject: [PATCH] adjust inconsistent dataclasses plugin error messages --- mypy/plugins/dataclasses.py | 4 ++-- test-data/unit/check-dataclass-transform.test | 4 ++-- test-data/unit/check-dataclasses.test | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mypy/plugins/dataclasses.py b/mypy/plugins/dataclasses.py index 75496d5e56f9..6306b3a77ae9 100644 --- a/mypy/plugins/dataclasses.py +++ b/mypy/plugins/dataclasses.py @@ -229,7 +229,7 @@ def transform(self) -> bool: # Add <, >, <=, >=, but only if the class has an eq method. if decorator_arguments["order"]: if not decorator_arguments["eq"]: - ctx.api.fail("eq must be True if order is True", ctx.cls) + ctx.api.fail('"eq" must be True if "order" is True', ctx.reason) for method_name in ["__lt__", "__gt__", "__le__", "__ge__"]: # Like for __eq__ and __ne__, we want "other" to match @@ -247,7 +247,7 @@ def transform(self) -> bool: if existing_method is not None and not existing_method.plugin_generated: assert existing_method.node ctx.api.fail( - f"You may not have a custom {method_name} method when order=True", + f'You may not have a custom "{method_name}" method when "order" is True', existing_method.node, ) diff --git a/test-data/unit/check-dataclass-transform.test b/test-data/unit/check-dataclass-transform.test index 1a25c087c5a6..00591d46f834 100644 --- a/test-data/unit/check-dataclass-transform.test +++ b/test-data/unit/check-dataclass-transform.test @@ -55,8 +55,8 @@ def my_dataclass(*, eq: bool, order: bool) -> Callable[[Type], Type]: return cls return transform -@my_dataclass(eq=False, order=True) -class Person: # E: eq must be True if order is True +@my_dataclass(eq=False, order=True) # E: "eq" must be True if "order" is True +class Person: name: str age: int diff --git a/test-data/unit/check-dataclasses.test b/test-data/unit/check-dataclasses.test index 631a92f9963b..4d85be391186 100644 --- a/test-data/unit/check-dataclasses.test +++ b/test-data/unit/check-dataclasses.test @@ -672,8 +672,8 @@ app1 >= app3 # flags: --python-version 3.7 from dataclasses import dataclass -@dataclass(eq=False, order=True) -class Application: # E: eq must be True if order is True +@dataclass(eq=False, order=True) # E: "eq" must be True if "order" is True +class Application: ... [builtins fixtures/dataclasses.pyi] @@ -684,7 +684,7 @@ from dataclasses import dataclass @dataclass(order=True) class Application: - def __lt__(self, other: 'Application') -> bool: # E: You may not have a custom __lt__ method when order=True + def __lt__(self, other: 'Application') -> bool: # E: You may not have a custom "__lt__" method when "order" is True ... [builtins fixtures/dataclasses.pyi]