44'''
55from jinja2 import Environment
66
7+ from typing import Any
8+
79from flatdata .generator .tree .nodes .resources import Instance , Vector , Multivector , RawData
810from flatdata .generator .tree .nodes .resources .archive import Archive as ArchiveResource
911from flatdata .generator .tree .nodes .trivial import Structure
@@ -22,18 +24,18 @@ def supported_nodes(self) -> list[type]:
2224 return [Structure , Archive ]
2325
2426 def _populate_environment (self , env : Environment ) -> None :
25- def _decorate_archive_type (tree , value ) :
27+ def _decorate_archive_type (tree : Any , value : Node ) -> str :
2628 assert isinstance (value , Node )
27- return tree .namespace_path (value , "_" ) + "_" + value .name
29+ return str ( tree .namespace_path (value , "_" ) + "_" + value .name )
2830
29- def to_python_doc (value ) :
31+ def to_python_doc (value : str ) -> str :
3032 return '\n ' .join (
3133 ["# " + line .replace ('/**' , '' , 1 ).replace ('*/' , '' , 1 ).replace (" *" , '' ,
3234 1 ).replace ("//" , "" ,
3335 1 ) for
3436 line in value .splitlines ()])
3537
36- def to_container (resource ) :
38+ def to_container (resource : Any ) -> str :
3739 if isinstance (resource , Instance ):
3840 return "flatdata.resources.Instance"
3941 if isinstance (resource , Vector ):
@@ -46,22 +48,22 @@ def to_container(resource):
4648 return "flatdata.archive.Archive"
4749 raise ValueError ("Unknown resource type: %s" % (resource .__class__ ))
4850
49- def to_initializer (resource , tree ) :
51+ def to_initializer (resource : Any , tree : Any ) -> str :
5052 if isinstance (resource , Instance ):
51- return _decorate_archive_type (tree , resource .referenced_structures [0 ].node )
53+ return str ( _decorate_archive_type (tree , resource .referenced_structures [0 ].node ) )
5254 if isinstance (resource , Vector ):
53- return _decorate_archive_type (tree , resource .referenced_structures [0 ].node )
55+ return str ( _decorate_archive_type (tree , resource .referenced_structures [0 ].node ) )
5456 if isinstance (resource , Multivector ):
5557 return "[{}]" .format (
5658 ',' .join ([_decorate_archive_type (tree , t .node ) for t in
5759 resource .referenced_structures ]))
5860 if isinstance (resource , ArchiveResource ):
59- return _decorate_archive_type (tree , resource .children [0 ].node ) # type: ignore[attr-defined] # child is an ArchiveReference which has .node
61+ return str ( _decorate_archive_type (tree , resource .children [0 ].node ) ) # type: ignore[attr-defined] # child is an ArchiveReference which has .node
6062 if isinstance (resource , RawData ):
6163 return "None"
6264 raise ValueError ("Unknown resource type: %s" % (resource .__class__ ))
6365
64- def to_dtype (field ) :
66+ def to_dtype (field : Any ) -> str :
6567 type_map = {
6668 "bool" : "?" ,
6769 "i8" : "b" ,
@@ -75,9 +77,9 @@ def to_dtype(field):
7577 }
7678 if field .type .name in type_map :
7779 return type_map [field .type .name ]
78- return type_map [field .type_reference .node .type .name ]
80+ return str ( type_map [field .type_reference .node .type .name ])
7981
80- def _safe_py_string_line (value ) :
82+ def _safe_py_string_line (value : str ) -> str :
8183 return value .replace ('\\ ' , '\\ \\ ' ).replace ('"' , r'\"' )
8284
8385 env .filters ["safe_py_string_line" ] = _safe_py_string_line
0 commit comments