Skip to content

[clang/python] Add type annotation to libclang Python binding #76664

Open
@linux4life798

Description

@linux4life798

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.

  1. 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.
  2. Type annotations have evolved a bit throughout Python 3 (ex. shift from using List[str] to list[str] OR Optional[str] to str | 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.

Helpful Resources:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions