[gi-docgen/ebassi/parse-array: 3/5] gir: Make array name optional




commit 22c79c53ee5f0dcedeee52377b4a756cdec379d5
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Nov 9 22:32:33 2021 +0000

    gir: Make array name optional
    
    We don't really need it.

 gidocgen/gir/ast.py    | 2 +-
 gidocgen/gir/parser.py | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/gidocgen/gir/ast.py b/gidocgen/gir/ast.py
index 8a7294a..5fe7fec 100644
--- a/gidocgen/gir/ast.py
+++ b/gidocgen/gir/ast.py
@@ -212,7 +212,7 @@ class Type(GIRElement):
 
 class ArrayType(GIRElement):
     """Base class for Array nodes"""
-    def __init__(self, name: str, value_type: Type, ctype: str = None, zero_terminated: bool = False,
+    def __init__(self, name: T.Optional[str], value_type: Type, ctype: T.Optional[str] = None, 
zero_terminated: bool = False,
                  fixed_size: int = -1, length: int = -1):
         super().__init__(name)
         self.ctype = ctype
diff --git a/gidocgen/gir/parser.py b/gidocgen/gir/parser.py
index 08d2d93..bfa18d5 100644
--- a/gidocgen/gir/parser.py
+++ b/gidocgen/gir/parser.py
@@ -332,7 +332,7 @@ class GirParser:
     def _parse_array(self, node: ET.Element) -> ast.Type:
         child = node.find('core:array', GI_NAMESPACES)
 
-        name = child.attrib.get('name') or node.attrib.get('name')
+        array_name = child.attrib.get('name')
         array_type = child.attrib.get(_cns('type'))
         attr_zero_terminated = child.attrib.get('zero-terminated')
         attr_fixed_size = child.attrib.get('fixed-size')
@@ -344,7 +344,7 @@ class GirParser:
             ttype = child_type.attrib.get(_cns('type'))
             tname = child_type.attrib.get('name')
             if tname is None and ttype is not None:
-                log.debug(f"Unlabled element type {ttype}")
+                log.debug(f"Unlabeled array element type {ttype}")
                 target = ast.Type(name=ttype.replace('*', ''), ctype=ttype)
             if tname == 'none' and ttype == 'void':
                 target = ast.VoidType()
@@ -376,7 +376,7 @@ class GirParser:
         if attr_length is not None:
             length = int(attr_length)
 
-        return ast.ArrayType(name=name, zero_terminated=zero_terminated,
+        return ast.ArrayType(name=array_name, zero_terminated=zero_terminated,
                              fixed_size=fixed_size, length=length,
                              ctype=array_type, value_type=target)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]