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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
adjust inconsistent dataclasses plugin error messages
  • Loading branch information
wesleywright committed Feb 7, 2023
commit f4179e5c5a182dd265b349c521dc415e46071f35
4 changes: 2 additions & 2 deletions mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)

Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-dataclass-transform.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down