Skip to content

Commit adbbb90

Browse files
authored
[libclang/python] Simplify __eq__ operators (#140540)
This allows us to remove a few type: ignores.
1 parent d76b9d6 commit adbbb90

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

clang/bindings/python/clang/cindex.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,9 @@ def is_in_system_header(self):
335335
return conf.lib.clang_Location_isInSystemHeader(self) # type: ignore [no-any-return]
336336

337337
def __eq__(self, other):
338-
if not isinstance(other, SourceLocation):
339-
return False
340-
return conf.lib.clang_equalLocations(self, other) # type: ignore [no-any-return]
338+
return isinstance(other, SourceLocation) and conf.lib.clang_equalLocations(
339+
self, other
340+
)
341341

342342
def __ne__(self, other):
343343
return not self.__eq__(other)
@@ -395,9 +395,9 @@ def end(self):
395395
return conf.lib.clang_getRangeEnd(self) # type: ignore [no-any-return]
396396

397397
def __eq__(self, other):
398-
if not isinstance(other, SourceRange):
399-
return False
400-
return conf.lib.clang_equalRanges(self, other) # type: ignore [no-any-return]
398+
return isinstance(other, SourceRange) and conf.lib.clang_equalRanges(
399+
self, other
400+
)
401401

402402
def __ne__(self, other):
403403
return not self.__eq__(other)
@@ -1599,9 +1599,7 @@ def from_location(tu: TranslationUnit, location: SourceLocation) -> Cursor | Non
15991599

16001600
# This function is not null-guarded because it is used in cursor_null_guard itself
16011601
def __eq__(self, other: object) -> bool:
1602-
if not isinstance(other, Cursor):
1603-
return False
1604-
return conf.lib.clang_equalCursors(self, other) # type: ignore [no-any-return]
1602+
return isinstance(other, Cursor) and conf.lib.clang_equalCursors(self, other)
16051603

16061604
# Not null-guarded for consistency with __eq__
16071605
def __ne__(self, other: object) -> bool:

0 commit comments

Comments
 (0)