[clang] Add comments and macros support to Python bindings (PR #81684)

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 13 15:17:48 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r fd3a0c185f177351207783fc2a604dac086cdaf7...497478f08570f1333966c0843d713268bc9ba5c7 clang/bindings/python/clang/cindex.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- cindex.py	2024-02-13 23:12:05.000000 +0000
+++ cindex.py	2024-02-13 23:17:41.291558 +0000
@@ -2260,21 +2260,22 @@
 TypeKind.EXTVECTOR = TypeKind(176)
 TypeKind.ATOMIC = TypeKind(177)
 
 ### Comment Kinds ###
 
+
 class CommentKind(BaseEnumeration):
     """
     Describes the kind of comment.
     """
 
     # The unique kind objects, indexed by id.
     _kinds = []
     _name_map = None
 
     def __repr__(self):
-        return 'CommentKind.%s' % (self.name,)
+        return "CommentKind.%s" % (self.name,)
 
 
 CommentKind.NULL = CommentKind(0)
 CommentKind.TEXT = CommentKind(1)
 CommentKind.INLINECOMMAND = CommentKind(2)
@@ -2292,16 +2293,17 @@
 
 class CommentInlineCommandRenderKind(BaseEnumeration):
     """
     Describes the kind of rendering mode of an inline command.
     """
+
     # The unique kind objects, indexed by id.
     _kinds = []
     _name_map = None
 
     def __repr__(self):
-        return 'CommentInlineCommandRenderKind.%s' % (self.name,)
+        return "CommentInlineCommandRenderKind.%s" % (self.name,)
 
 
 CommentInlineCommandRenderKind.NORMAL = CommentInlineCommandRenderKind(0)
 CommentInlineCommandRenderKind.BOLD = CommentInlineCommandRenderKind(1)
 CommentInlineCommandRenderKind.MONOSPACED = CommentInlineCommandRenderKind(2)
@@ -2311,22 +2313,22 @@
 class CommentParamPassDirection(BaseEnumeration):
     """
     Describes the kind of parameter passing direction for \\param
     or \\arg command
     """
+
     # The unique kind objects, indexed by id.
     _kinds = []
     _name_map = None
 
     def __repr__(self):
-        return 'CommentParamPassDirection.%s' % (self.name,)
+        return "CommentParamPassDirection.%s" % (self.name,)
 
 
 CommentParamPassDirection.IN = CommentParamPassDirection(0)
 CommentParamPassDirection.OUT = CommentParamPassDirection(1)
 CommentParamPassDirection.INOU = CommentParamPassDirection(2)
-
 
 
 class RefQualifierKind(BaseEnumeration):
     """Describes a specific ref-qualifier of a type."""
 
@@ -3655,14 +3657,17 @@
     None, c_object_p, POINTER(SourceLocation), c_uint, py_object
 )
 callbacks["cursor_visit"] = CFUNCTYPE(c_int, Cursor, Cursor, py_object)
 callbacks["fields_visit"] = CFUNCTYPE(c_int, Cursor, py_object)
 
+
 class CXTranslationUnitImpl(Structure):
-    pass # opaque structure
+    pass  # opaque structure
+
 
 CXTranslationUnit = POINTER(CXTranslationUnitImpl)
+
 
 class Comment(Structure):
     _fields_ = [("ASTNode", c_void_p), ("TranslationUnit", CXTranslationUnit)]
 
     def get_text(self):
@@ -3678,10 +3683,11 @@
         """Get number of child nodes."""
         return conf.lib.clang_Comment_getNumChildren(self)
 
     def get_children(self):
         """Return an iterator for accessing the children of this comment."""
+
         def cast_child(child):
             if child.kind == CommentKind.INLINECOMMAND:
                 child.__class__ = InlineCommand
             if child.kind == CommentKind.HTMLSTARTTAG:
                 child.__class__ = HTMLComment
@@ -3690,23 +3696,25 @@
             if child.kind == CommentKind.BLOCKCOMMAND:
                 child.__class__ = BlockCommandComment
             if child.kind == CommentKind.PARAMCOMMAND:
                 child.__class__ = ParamCommandComment
             if child.kind == CommentKind.TPARAMCOMMAND:
-                child.__class__ =  TParamCommandComment
+                child.__class__ = TParamCommandComment
             if child.kind == CommentKind.VERBATIMBLOCKLINE:
                 child.__class__ = VerbatimBlockLineComment
             if child.kind == CommentKind.VERBATIMLINE:
                 child.__class__ = VerbatimLineComment
             if child.kind == CommentKind.FULLCOMMENT:
                 child.__class__ = FullComment
             # if child.kind == CommentKind.PARAGRAPH:
             # if child.kind == CommentKind.VERBATIMBLOCKCOMMAND:
             return child
 
-        return (cast_child(conf.lib.clang_Comment_getChild(self, i))
-                for i in range(self.num_children()))
+        return (
+            cast_child(conf.lib.clang_Comment_getChild(self, i))
+            for i in range(self.num_children())
+        )
 
     def is_whitespace(self):
         """Check if all paragraph nodes are space or empty."""
         return conf.lib.clang_Comment_isWhitespace(self)
 
@@ -3727,12 +3735,14 @@
 
     def get_num_args(self):
         conf.lib.clang_InlineCommandComment_getNumArgs(self)
 
     def get_args(self):
-        return (conf.lib.clang_InlineCommandComment_getArgText(self, i)
-                for i in range(self.get_num_args()))
+        return (
+            conf.lib.clang_InlineCommandComment_getArgText(self, i)
+            for i in range(self.get_num_args())
+        )
 
 
 class HTMLComment(Comment):
     def get_tag_name(self):
         return conf.lib.clang_HTMLTagComment_getTagName(self)
@@ -3742,28 +3752,34 @@
 
     def get_num_attrs(self):
         return conf.lib.clang_HTMLStartTag_getNumAttrs(self)
 
     def get_attrs(self):
-        return (conf.lib.clang_HTMLStartTag_getAttrName(self, i)
-                for i in range(self.get_num_attrs()))
+        return (
+            conf.lib.clang_HTMLStartTag_getAttrName(self, i)
+            for i in range(self.get_num_attrs())
+        )
 
     def get_attr_values(self):
-        return (conf.lib.clang_HTMLStartTag_getAttrValue(self, i)
-                for i in range(self.get_num_attrs()))
+        return (
+            conf.lib.clang_HTMLStartTag_getAttrValue(self, i)
+            for i in range(self.get_num_attrs())
+        )
 
 
 class BlockCommandComment(Comment):
     def get_command_name(self):
         return conf.lib.clang_BlockCommandComment_getCommandName(self)
 
     def get_num_args(self):
         return conf.lib.clang_BlockCommandComment_getNumArgs(self)
 
     def get_args(self):
-        return (conf.lib.clang_BlockCommandComment_getArgText(self, i)
-                for i in range(self.get_num_args()))
+        return (
+            conf.lib.clang_BlockCommandComment_getArgText(self, i)
+            for i in range(self.get_num_args())
+        )
 
     def get_paragraph(self):
         return conf.lib.clang_BlockCommandComment_getParagraph(self)
 
 
@@ -3793,12 +3809,14 @@
 
     def get_depth(self):
         return conf.lib.clang_TParamCommandComment_getDepth(self)
 
     def get_index(self):
-        return (conf.lib.clang_TParamCommandComment_getIndex(self, i)
-                for i in range(self.get_depth()))
+        return (
+            conf.lib.clang_TParamCommandComment_getIndex(self, i)
+            for i in range(self.get_depth())
+        )
 
 
 def VerbatimBlockLineComment(Comment):
     def get_text(self):
         return conf.lib.clang_VerbatimBlockLineComment_getText(self)
@@ -4112,37 +4130,82 @@
     ("clang_Comment_getNumChildren", [Comment], c_uint),
     ("clang_Comment_getChild", [Comment, c_uint], Comment),
     ("clang_Comment_isWhitespace", [Comment], c_uint),
     ("clang_InlineContentComment_hasTrailingNewline", [Comment], c_uint),
     ("clang_TextComment_getText", [Comment], _CXString, _CXString.from_result),
-    ("clang_InlineCommandComment_getCommandName", [Comment], _CXString, _CXString.from_result),
+    (
+        "clang_InlineCommandComment_getCommandName",
+        [Comment],
+        _CXString,
+        _CXString.from_result,
+    ),
     ("clang_InlineCommandComment_getRenderKind", [Comment], c_uint),
     ("clang_InlineCommandComment_getNumArgs", [Comment], c_uint),
-    ("clang_InlineCommandComment_getArgText", [Comment, c_uint], _CXString, _CXString.from_result),
+    (
+        "clang_InlineCommandComment_getArgText",
+        [Comment, c_uint],
+        _CXString,
+        _CXString.from_result,
+    ),
     ("clang_HTMLTagComment_getTagName", [Comment], _CXString, _CXString.from_result),
     ("clang_HTMLStartTagComment_isSelfClosing", [Comment], c_uint),
     ("clang_HTMLStartTag_getNumAttrs", [Comment], c_uint),
-    ("clang_HTMLStartTag_getAttrName", [Comment, c_uint], _CXString, _CXString.from_result),
-    ("clang_HTMLStartTag_getAttrValue", [Comment, c_uint], _CXString, _CXString.from_result),
-    ("clang_BlockCommandComment_getCommandName", [Comment], _CXString, _CXString.from_result),
+    (
+        "clang_HTMLStartTag_getAttrName",
+        [Comment, c_uint],
+        _CXString,
+        _CXString.from_result,
+    ),
+    (
+        "clang_HTMLStartTag_getAttrValue",
+        [Comment, c_uint],
+        _CXString,
+        _CXString.from_result,
+    ),
+    (
+        "clang_BlockCommandComment_getCommandName",
+        [Comment],
+        _CXString,
+        _CXString.from_result,
+    ),
     ("clang_BlockCommandComment_getNumArgs", [Comment], c_uint),
-    ("clang_BlockCommandComment_getArgText", [Comment, c_uint], _CXString, _CXString.from_result),
+    (
+        "clang_BlockCommandComment_getArgText",
+        [Comment, c_uint],
+        _CXString,
+        _CXString.from_result,
+    ),
     ("clang_BlockCommandComment_getParagraph", [Comment], Comment),
-    ("clang_ParamCommandComment_getParamName", [Comment], _CXString, _CXString.from_result),
+    (
+        "clang_ParamCommandComment_getParamName",
+        [Comment],
+        _CXString,
+        _CXString.from_result,
+    ),
     ("clang_ParamCommandComment_isParamIndexValid", [Comment], c_uint),
     ("clang_ParamCommandComment_getParamIndex", [Comment], c_uint),
     ("clang_ParamCommandComment_isDirectionExplicit", [Comment], c_uint),
     ("clang_ParamCommandComment_getDirection", [Comment], CommentParamPassDirection),
-    ("clang_TParamCommandComment_getParamName", [Comment], _CXString, _CXString.from_result),
+    (
+        "clang_TParamCommandComment_getParamName",
+        [Comment],
+        _CXString,
+        _CXString.from_result,
+    ),
     ("clang_TParamCommandComment_isParamPositionValid", [Comment], c_uint),
     ("clang_TParamCommandComment_getDepth", [Comment], c_uint),
     ("clang_TParamCommandComment_getIndex", [Comment, c_uint], c_uint),
-    ("clang_VerbatimBlockLineComment_getText", [Comment], _CXString, _CXString.from_result),
+    (
+        "clang_VerbatimBlockLineComment_getText",
+        [Comment],
+        _CXString,
+        _CXString.from_result,
+    ),
     ("clang_VerbatimLineComment_getText", [Comment], _CXString, _CXString.from_result),
     ("clang_HTMLTagComment_getAsString", [Comment], _CXString, _CXString.from_result),
     ("clang_FullComment_getAsHTML", [Comment], _CXString, _CXString.from_result),
-    ("clang_FullComment_getAsXML", [Comment], _CXString, _CXString.from_result)
+    ("clang_FullComment_getAsXML", [Comment], _CXString, _CXString.from_result),
 ]
 
 
 class LibclangError(Exception):
     def __init__(self, message):

``````````

</details>


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


More information about the cfe-commits mailing list