Skip to content

Commit

Permalink
fix: generator: VOID can also be Any other than None
Browse files Browse the repository at this point in the history
  • Loading branch information
matperc committed Sep 22, 2023
1 parent 4d0eb2b commit 60ee578
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tools/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ def _type_to_python(

if tag == tags.ARRAY:
array_type = type.get_param_type(0)
t = _type_to_python(array_type, current_namespace, needed_namespaces)
t = _type_to_python(
array_type, current_namespace, needed_namespaces, cant_be_none=True
)
if out_arg:
# As output argument array of type uint8 are returned as bytes
if array_type.get_tag() == GI.TypeTag.UINT8:
Expand All @@ -278,7 +280,9 @@ def _type_to_python(

if tag in (tags.GLIST, tags.GSLIST):
array_type = type.get_param_type(0)
t = _type_to_python(array_type, current_namespace, needed_namespaces)
t = _type_to_python(
array_type, current_namespace, needed_namespaces, cant_be_none=True
)
return f"list[{t}]"

if tag == tags.BOOLEAN:
Expand All @@ -297,8 +301,12 @@ def _type_to_python(
if tag == tags.GHASH:
key_type = type.get_param_type(0)
value_type = type.get_param_type(1)
kt = _type_to_python(key_type, current_namespace, needed_namespaces)
vt = _type_to_python(value_type, current_namespace, needed_namespaces)
kt = _type_to_python(
key_type, current_namespace, needed_namespaces, cant_be_none=True
)
vt = _type_to_python(
value_type, current_namespace, needed_namespaces, cant_be_none=True
)
return f"dict[{kt}, {vt}]"

if tag in (tags.FILENAME, tags.UTF8, tags.UNICHAR):
Expand Down Expand Up @@ -360,6 +368,8 @@ def _type_to_python(
return f"{namespace}.{name}"

if tag == tags.VOID:
if cant_be_none:
return "Any"
return "None"

raise ValueError("TODO")
Expand Down Expand Up @@ -848,7 +858,9 @@ def _gi_build_stub(
continue
names.append(n)
type = _build_type(GIRepository.property_info_get_type(p))
t = _type_to_python(type, current_namespace, needed_namespaces)
t = _type_to_python(
type, current_namespace, needed_namespaces, cant_be_none=True
)
setter = GIRepository.property_info_get_setter(p)
if setter:
arg_info = GIRepository.callable_info_get_arg(setter, 0)
Expand Down

0 comments on commit 60ee578

Please sign in to comment.