Skip to content

Commit

Permalink
Output ... when generating interfaces without members
Browse files Browse the repository at this point in the history
Otherwise the body of the class will be empty which raises the
syntax error.
  • Loading branch information
igo95862 committed Oct 29, 2023
1 parent 8af9ea3 commit 3ab1f00
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/sdbus/interface_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ def __init__(self, element: Element):
else:
raise ValueError(f'Unknown D-Bus member {dbus_member}')

@property
def has_members(self) -> bool:
return any((self.methods, self.properties, self.signals))


SKIP_INTERFACES = {
'org.freedesktop.DBus.Properties',
Expand All @@ -549,6 +553,7 @@ def __init__(self, element: Element):
}

INTERFACE_TEMPLATES: Dict[str, str] = {
"generic_no_members": r"... # Interface has no members",
"generic_method_flags": (
r"""
{%- if method.dbus_input_signature %}
Expand Down Expand Up @@ -609,6 +614,7 @@ def __init__(self, element: Element):
interface_name="{{ interface.interface_name }}",
):
{%- filter indent -%}
{%- if interface.has_members -%}
{% for method in interface.methods -%}
{% include 'async_method' %}
{% endfor -%}
Expand All @@ -618,6 +624,9 @@ def __init__(self, element: Element):
{% for signal in interface.signals -%}
{% include 'async_signal' %}
{% endfor -%}
{%- else %}
{% include 'generic_no_members' %}
{% endif -%}
{%- endfilter -%}
"""
),
Expand Down Expand Up @@ -693,12 +702,16 @@ def {{ signal.python_name }}(self) -> {{ signal.typing }}:
interface_name="{{ interface.interface_name }}",
):
{%- filter indent -%}
{%- if interface.has_members -%}
{% for method in interface.methods -%}
{% include 'blocking_method' %}
{% endfor -%}
{% for a_property in interface.properties -%}
{% include 'blocking_property' %}
{% endfor -%}
{%- else %}
{% include 'generic_no_members' %}
{% endif -%}
{%- endfilter -%}
"""
),
Expand Down

0 comments on commit 3ab1f00

Please sign in to comment.