Open
Description
The libclang Python binding needs type annotations. Type annotations are important for libraries because they enable the IDE to help users learn the API and steer them in the correct direction through code completions. Furthermore, they allow the IDEs + static checkers to identify a large range of misuse errors.
This topic has been discussed a bit in DeinAlptraum's conversation on Discourse.
There are a few issues that would need to be addressed before we can simply merge type annotations into the python files.
- The straightforward way to implement type annotations requires Python 3, but the main cindex.py still makes mention of Python 2.
- We should be dropping Python 2 support.
- Type annotations have evolved a bit throughout Python 3 (ex. shift from using
List[str]
tolist[str]
OROptional[str]
tostr | None
). Using the newer syntax/style may make the library incompatible with earlier versions of Python 3. So, we need to figure out a reasonable Python 3 version cutoff and implement CI checks to ensure compatibility with the earliest version we want to support.- Python 3.7 might be a good cutoff. This aligns with Debian buster (previous previous stable).
- Issue [clang/python] Add Python libclang unit tests to CI #76601 should add CI to check with older python versions.
Helpful Resources:
- https://discourse.llvm.org/t/type-annotations-for-libclang-python-bindings/70644/9
- 83768e6
- https://typing.readthedocs.io/en/latest/source/best_practices.html
- https://docs.python.org/3/whatsnew/3.7.html#pep-560-core-support-for-typing-module-and-generic-types
- https://peps.python.org/pep-0585
- https://stackoverflow.com/questions/63939138/is-there-a-way-to-use-python-3-9-type-hinting-in-its-previous-versions