[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-15 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/95608 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-14 Thread Jannick Kremer via cfe-commits
DeinAlptraum wrote: @Endilll can I ask you for a review again? As a next step towards the python-bindings strict typing PR, this one captures all the enum refactoring changes necessary towards that goal. Don't be scared by the LoC changed: 90% of that is just indentation changes :)

[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-14 Thread Jannick Kremer via cfe-commits
@@ -611,51 +612,25 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration: +class BaseEnumeration(Enum): """ Common base class for named enumerations held in sync with Index.h values. - -Subclasses must define their own _kinds and _name_map

[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-14 Thread Jannick Kremer via cfe-commits
@@ -611,51 +612,25 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration: +class BaseEnumeration(Enum): """ Common base class for named enumerations held in sync with Index.h values. - -Subclasses must define their own _kinds and _name_map

[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-14 Thread Jannick Kremer via cfe-commits
@@ -31,17 +31,9 @@ class TestCursorKind(unittest.TestCase): def test_from_id(self): """Check that kinds can be constructed from valid IDs""" for enum in self.enums: -self.assertEqual(enum.from_id(2), enum._kinds[2]) +

[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-14 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum commented: There is also `TokenKind`: this one does not currently inherit from `BaseEnumeration` and is defined somewhat differently, having all its variants and their IDs as a dictionary in `enumerations.py`. This seems quite arbitrary to me, is there any

[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-14 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/95608 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-14 Thread Jannick Kremer via cfe-commits
@@ -611,51 +612,25 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration: +class BaseEnumeration(Enum): """ Common base class for named enumerations held in sync with Index.h values. - -Subclasses must define their own _kinds and _name_map

[clang] [libclang/python] Refactor enum usage (PR #95608)

2024-06-14 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum created https://github.com/llvm/llvm-project/pull/95608 Use Python's builtin enum class instead of writing our own. This is preparation for passing a strict type check in PR #78114 , fixing 920 out of 1341 strict typing errors >From

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
DeinAlptraum wrote: @Endilll I merged the Python 3.8 CI into this PR and the CI run was successful (though it only ran on 3.8 for some reason), so can this be merged? https://github.com/llvm/llvm-project/pull/95381 ___ cfe-commits mailing list

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/95381 >From a3da142b0db6581581ccb135800d77b09476f385 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Thu, 13 Jun 2024 10:43:52 +0100 Subject: [PATCH 1/2] [libclang/python] Fix bugs in custom enum

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
DeinAlptraum wrote: These were all the bugs I'd found, so I think it is https://github.com/llvm/llvm-project/pull/95381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
@@ -0,0 +1,50 @@ +import unittest + +from clang.cindex import ( +CursorKind, +TemplateArgumentKind, +ExceptionSpecificationKind, +AvailabilityKind, +AccessSpecifier, +TypeKind, +RefQualifierKind, +LinkageKind, +TLSKind, +StorageClass, +) +

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/95381 >From a3da142b0db6581581ccb135800d77b09476f385 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Thu, 13 Jun 2024 10:43:52 +0100 Subject: [PATCH 1/2] [libclang/python] Fix bugs in custom enum

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/95381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
@@ -1336,7 +1336,7 @@ def __repr__(self): CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271) # OpenMP teams distribute simd directive. -CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(272) +CursorKind.OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(272)

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum updated https://github.com/llvm/llvm-project/pull/95381 >From bfc36e30e84c616adb8ff57754a49a5bb66d1dd9 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Thu, 13 Jun 2024 10:43:52 +0100 Subject: [PATCH] [libclang/python] Fix bugs in custom enum implementation

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
@@ -2395,7 +2395,7 @@ def __repr__(self): TypeKind.OCLRESERVEID = TypeKind(160) TypeKind.OBJCOBJECT = TypeKind(161) -TypeKind.OBJCCLASS = TypeKind(162) +TypeKind.OBJCTYPEPARAM = TypeKind(162) DeinAlptraum wrote: This was a duplicate with variant 28

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
DeinAlptraum wrote: @Endilll I separated the fixes for the enum bugs from the strict typing PR, and added tests that cover these cases. I checked that the tests fail before the fixes and succeed now. https://github.com/llvm/llvm-project/pull/95381

[clang] [libclang/python] Fix bugs in custom enum implementation and add tests (PR #95381)

2024-06-13 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum created https://github.com/llvm/llvm-project/pull/95381 Do not allow initialization of enum from negative IDs (e.g. from_id(-1) currently produces the last known variant) Rename duplicate enums: CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE and TypeKind.OBJCCLASS

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-11 Thread Jannick Kremer via cfe-commits
DeinAlptraum wrote: Thanks a lot for your feedback! Yup I get that the PR is pretty big and might still need significant changes. > 1. I have maintainability concerns about `ClangLib` protocol [...] I completely agree that this is ugly, but I didn't find a better solution that would

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-10 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-10 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-10 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [libclang/python] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits
DeinAlptraum wrote: Since https://github.com/llvm/llvm-project/issues/83962 is now closed and the minimum Python version updated to 3.8, this is now finally ready for review. I've updated this with the changes to the Python bindings of the past couple months. I have no idea idea what the

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum ready_for_review https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits
@@ -2286,192 +2869,151 @@ class TypeKind(BaseEnumeration): Describes the kind of type. """ -# The unique kind objects, indexed by id. -_kinds = [] -_name_map = None - @property -def spelling(self): +def spelling(self) -> str:

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits
@@ -665,867 +1312,858 @@ class CursorKind(BaseEnumeration): A CursorKind describes the kind of entity that a cursor points to. """ -# The required BaseEnumeration declarations. -_kinds = [] -_name_map = None - @staticmethod -def get_all_kinds(): +

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-06-09 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-15 Thread Jannick Kremer via cfe-commits
DeinAlptraum wrote: I was just made aware of [some](https://github.com/llvm/llvm-project/pull/77219) [changes](https://github.com/llvm/llvm-project/pull/77228) by @linux4life798 that seem reasonable to merge before this, so I've returned this to draft status for now. Sorry for the

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-15 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum converted_to_draft https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
DeinAlptraum wrote: @AaronBallman could you review this or recommend reviewers? I didn't see any category in `clang/CodeOwners.rst` that seems to cover the bindings. https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -1722,23 +2300,23 @@ def location(self): return self._loc @property -def linkage(self): +def linkage(self) -> LinkageKind: """Return the linkage of this cursor.""" if not hasattr(self, "_linkage"): self._linkage =

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -67,89 +67,690 @@ import clang.enumerations import os -import sys - -if sys.version_info[0] == 3: -# Python 3 strings are unicode, translate them to/from utf8 for C-interop. -class c_interop_string(c_char_p): -def __init__(self, p=None): -if p

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -2341,30 +2830,32 @@ class Type(Structure): _fields_ = [("_kind_id", c_int), ("data", c_void_p * 2)] +_tu: TranslationUnit + @property -def kind(self): +def kind(self) -> TypeKind: """Return the kind of this type.""" return

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -67,89 +67,690 @@ import clang.enumerations import os -import sys - -if sys.version_info[0] == 3: -# Python 3 strings are unicode, translate them to/from utf8 for C-interop. -class c_interop_string(c_char_p): -def __init__(self, p=None): -if p

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -67,89 +67,690 @@ import clang.enumerations import os -import sys - -if sys.version_info[0] == 3: -# Python 3 strings are unicode, translate them to/from utf8 for C-interop. -class c_interop_string(c_char_p): -def __init__(self, p=None): -if p

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
https://github.com/DeinAlptraum edited https://github.com/llvm/llvm-project/pull/78114 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -232,13 +840,16 @@ class _CXString(Structure): _fields_ = [("spelling", c_char_p), ("free", c_int)] -def __del__(self): +def __del__(self) -> None: conf.lib.clang_disposeString(self) @staticmethod -def from_result(res, fn=None, args=None):

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -3968,7 +4500,7 @@ def function_exists(self, name): return True -def register_enumerations(): +def register_enumerations() -> None: DeinAlptraum wrote: This implementation dynamically adds the TokenKind variants, which means it also suffers from

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -642,51 +1259,29 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration(object): -""" -Common base class for named enumerations held in sync with Index.h values. +TEnum = TypeVar("TEnum", bound="BaseEnumeration") -Subclasses must define

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -642,51 +1259,29 @@ def register(value, name): ### Cursor Kinds ### -class BaseEnumeration(object): -""" -Common base class for named enumerations held in sync with Index.h values. +TEnum = TypeVar("TEnum", bound="BaseEnumeration") -Subclasses must define

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -67,89 +67,690 @@ import clang.enumerations import os -import sys - -if sys.version_info[0] == 3: -# Python 3 strings are unicode, translate them to/from utf8 for C-interop. -class c_interop_string(c_char_p): -def __init__(self, p=None): -if p

[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-14 Thread Jannick Kremer via cfe-commits
@@ -67,89 +67,690 @@ import clang.enumerations import os -import sys - -if sys.version_info[0] == 3: -# Python 3 strings are unicode, translate them to/from utf8 for C-interop. -class c_interop_string(c_char_p): -def __init__(self, p=None): -if p