Skip to content

Commit a5f09da

Browse files
committed
Add SourceLocation.__eq__ to make it comparable to the formatted form
1 parent 837ee66 commit a5f09da

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/graphql/language/location.py

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ class SourceLocation(NamedTuple):
1616
def formatted(self):
1717
return dict(line=self.line, column=self.column)
1818

19+
def __eq__(self, other):
20+
if isinstance(other, dict):
21+
return other == self.formatted
22+
return super().__eq__(other)
23+
24+
def __ne__(self, other):
25+
if isinstance(other, dict):
26+
return other != self.formatted
27+
return super().__ne__(other)
28+
1929

2030
def get_location(source: "Source", position: int) -> SourceLocation:
2131
"""Get the line and column for a character position in the source.

tests/error/test_format_error.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def format_graphql_error():
3131
extensions=extensions,
3232
)
3333
formatted = format_error(error)
34+
assert error == formatted
3435
assert formatted == {
3536
"message": "test message",
3637
"locations": [{"line": 2, "column": 14}, {"line": 3, "column": 20}],

0 commit comments

Comments
 (0)