[clang] [libclang/python] Add some logical typing changes. (PR #138074)

Jannick Kremer via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 30 18:52:41 PDT 2025


================
@@ -314,6 +316,8 @@ 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
----------------
DeinAlptraum wrote:

Currently, the `__eq__` operators in the Python bindings error out if you pass in a non-conforming object (say, `some_location == "hello"`. The `__eq__`  is expected to deal correctly with all types of objects, so this leads to a typing error if we were to annotate it as `def __eq__(self, other: SourceLocation):`

https://github.com/llvm/llvm-project/pull/138074


More information about the cfe-commits mailing list