-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libclang/python] Simplify __eq__ operators #140540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This allows us to remove a few type: ignores
@llvm/pr-subscribers-clang Author: Jannick Kremer (DeinAlptraum) ChangesThis allows us to remove a few type: ignores. Full diff: https://github.com/llvm/llvm-project/pull/140540.diff 1 Files Affected:
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:
|
✅ With the latest revision this PR passed the Python code formatter. |
wth is going on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the diff show that you add __ne__
operator, even though it's already present? What am I missing?
llvm-project/clang/bindings/python/clang/cindex.py
Lines 397 to 403 in f3d36b1
def __eq__(self, other): | |
if not isinstance(other, SourceRange): | |
return False | |
return conf.lib.clang_equalRanges(self, other) # type: ignore [no-any-return] | |
def __ne__(self, other): | |
return not self.__eq__(other) |
@Endilll I don't see the |
Indeed, I was looking at that commit instead of all changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we no longer need # type: ignore [no-any-return]
?
The |
This allows us to remove a few type: ignores.