[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 31 02:32:47 PDT 2024
================
@@ -255,71 +263,75 @@ class SourceLocation(Structure):
"""
_fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
- _data = None
+ _data: tuple[File | None, int, int, int] | None = None
- def _get_instantiation(self):
+ def _get_instantiation(self) -> tuple[File | None, int, int, int]:
if self._data is None:
f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
conf.lib.clang_getInstantiationLocation(
self, byref(f), byref(l), byref(c), byref(o)
)
if f:
- f = File(f)
+ file = File(f)
else:
- f = None
- self._data = (f, int(l.value), int(c.value), int(o.value))
+ file = None
+ self._data = (file, int(l.value), int(c.value), int(o.value))
return self._data
@staticmethod
- def from_position(tu, file, line, column):
+ def from_position(
+ tu: TranslationUnit, file: File, line: int, column: int
+ ) -> SourceLocation:
"""
Retrieve the source location associated with a given file/line/column in
a particular translation unit.
"""
- return conf.lib.clang_getLocation(tu, file, line, column)
+ return conf.lib.clang_getLocation(tu, file, line, column) # type: ignore [no-any-return]
@staticmethod
- def from_offset(tu, file, offset):
+ def from_offset(tu: TranslationUnit, file: File, offset: int) -> SourceLocation:
"""Retrieve a SourceLocation from a given character offset.
tu -- TranslationUnit file belongs to
file -- File instance to obtain offset from
offset -- Integer character offset within file
"""
- return conf.lib.clang_getLocationForOffset(tu, file, offset)
+ return conf.lib.clang_getLocationForOffset(tu, file, offset) # type: ignore [no-any-return]
----------------
DeinAlptraum wrote:
I've opened a PR separating these at #101310
https://github.com/llvm/llvm-project/pull/78114
More information about the cfe-commits
mailing list