[clang] [libclang/python] Fix some type errors, add type annotations (PR #98745)

Jannick Kremer via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 6 04:26:00 PDT 2024


================
@@ -64,48 +64,80 @@
 
 from ctypes import *
 
-import collections.abc
 import os
+import sys
 from enum import Enum
 
+from typing import (
+    Any,
+    Callable,
+    Generic,
+    Optional,
+    Type as TType,
+    TypeVar,
+    TYPE_CHECKING,
+    Union as TUnion,
+)
+
+if TYPE_CHECKING:
+    from ctypes import _Pointer
+    from typing_extensions import Protocol, TypeAlias
----------------
DeinAlptraum wrote:

There is no strict requirement for `typing_extensions` to be available, though all type checkers I've seen are either written in Python and depend on `typing_extensions` themselves  (the default checker `mypy`, Google's `pytype`, Facebook's `pyre`), or don't use Python at all (Microsoft's `pyright`) in which case the installed modules don't matter
Aside from that, as `TYPE_CHECKING` mode doesn't actually include any execution, the module not being installed would never lead to an error. At most, the type checker would complain that it can't resolve the import.

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


More information about the cfe-commits mailing list