Skip to content

Commit 7a027f3

Browse files
committed
fix: Generator: Convert Flags with invalid names to int
1 parent d8b0148 commit 7a027f3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tools/generate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ def _callable_get_arguments(
189189

190190

191191
class TypeInfo:
192+
193+
# This struct tries to emulate gi.TypeInfo
194+
192195
def __init__(
193196
self,
194197
obj: Any,
@@ -218,6 +221,9 @@ def get_name(self) -> str:
218221
def get_namespace(self) -> str:
219222
return self.obj.get_namespace()
220223

224+
def get_type(self) -> GIRepository.InfoType:
225+
return self.obj.get_type()
226+
221227

222228
def _build_type(type: GIRepository.BaseInfo) -> TypeInfo:
223229
return TypeInfo(
@@ -315,6 +321,15 @@ def _type_to_python(
315321
namespace = interface.get_namespace()
316322
name = interface.get_name()
317323

324+
if not re.match(_identifier_re, name):
325+
# Convert Flags and Enums with invalid name to int
326+
# Example NM 1.0 library
327+
if interface.get_type() in (
328+
GIRepository.InfoType.FLAGS,
329+
GIRepository.InfoType.ENUM,
330+
):
331+
return "int"
332+
318333
if namespace == "GObject" and name == "Value":
319334
return "typing.Any"
320335

0 commit comments

Comments
 (0)