[clang] [libclang/python] Simplify __eq__ operators (PR #140540)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Mon May 19 06:37:53 PDT 2025
https://github.com/DeinAlptraum created https://github.com/llvm/llvm-project/pull/140540
This allows us to remove a few type: ignores.
>From 51df5f4eb979edb7cc761276fe846626641bd6b4 Mon Sep 17 00:00:00 2001
From: Jannick Kremer <jannick.kremer at mailbox.org>
Date: Mon, 19 May 2025 22:36:05 +0900
Subject: [PATCH] [libclang/python] Simplfy __eq__ operators This allows us to
remove a few type: ignores
---
clang/bindings/python/clang/cindex.py | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 6f7243cdf80ac..a9f69309f4f67 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -335,9 +335,7 @@ def is_in_system_header(self):
return conf.lib.clang_Location_isInSystemHeader(self) # type: ignore [no-any-return]
def __eq__(self, other):
- if not isinstance(other, SourceLocation):
- return False
- return conf.lib.clang_equalLocations(self, other) # type: ignore [no-any-return]
+ return isinstance(other, SourceLocation) and conf.lib.clang_equalLocations(self, other)
def __ne__(self, other):
return not self.__eq__(other)
@@ -395,9 +393,7 @@ def end(self):
return conf.lib.clang_getRangeEnd(self) # type: ignore [no-any-return]
def __eq__(self, other):
- if not isinstance(other, SourceRange):
- return False
- return conf.lib.clang_equalRanges(self, other) # type: ignore [no-any-return]
+ return isinstance(other, SourceRange) and conf.lib.clang_equalRanges(self, other)
def __ne__(self, other):
return not self.__eq__(other)
@@ -1599,9 +1595,7 @@ def from_location(tu: TranslationUnit, location: SourceLocation) -> Cursor | Non
# This function is not null-guarded because it is used in cursor_null_guard itself
def __eq__(self, other: object) -> bool:
- if not isinstance(other, Cursor):
- return False
- return conf.lib.clang_equalCursors(self, other) # type: ignore [no-any-return]
+ return isinstance(other, Cursor) and conf.lib.clang_equalCursors(self, other)
# Not null-guarded for consistency with __eq__
def __ne__(self, other: object) -> bool:
More information about the cfe-commits
mailing list