Skip to content

Commit

Permalink
python-flake-8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikDeSmedt committed Feb 19, 2024
1 parent c995704 commit 72a2d5e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
6 changes: 3 additions & 3 deletions contrib/msggen/msggen/gen/grpc/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def generate_array(self, prefix, field: ArrayField, override):
if isinstance(field.itemtype, CompositeField):
self.generate_composite(prefix, field.itemtype, override)

def generate_composite(self, prefix, field: CompositeField, override = None):
def generate_composite(self, prefix, field: CompositeField, override=None):
"""Generates the conversions from JSON-RPC to GRPC.
"""
if field.omit():
return

if override is None:
override = lambda x : x
override = lambda x: x

# First pass: generate any sub-fields before we generate the
# top-level field itself.
Expand Down
21 changes: 10 additions & 11 deletions contrib/msggen/msggen/gen/grpc/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def enumerate_enum(self, typename, variants):
for v in variants:
yield (self.enumvar2number(typename, v), v)

def gather_method_types(self, methods : List[Method]):
def gather_method_types(self, methods: List[Method]):
"""Gather all types that might need to be defined.
"""
types = []
Expand All @@ -98,8 +98,8 @@ def gather_method_types(self, methods : List[Method]):
types.extend(gather_subfields(field))

return types
def gather_notification_types(self, notifications : List[Notification]):

def gather_notification_types(self, notifications: List[Notification]):
"""Gather all types that might need to be defined
to represent notifications
"""
Expand Down Expand Up @@ -130,15 +130,14 @@ def generate_service(self, service: Service) -> None:
response_type_name = notification_typename_overrides(notification.response.typename)
self.write(
f" rpc Subscribe{name}({notification.request.typename}) returns (stream {response_type_name}) {{}}\n",
cleanup=False)
cleanup=False)

self.write(f"""}}
""")

def generate_enum(self, e: EnumField, indent=0, typename_override = None):
def generate_enum(self, e: EnumField, indent=0, typename_override=None):
if typename_override is None:
typename_override = lambda x : x

typename_override = lambda x: x

self.logger.debug(f"Generating enum {e}")
prefix = "\t" * indent
Expand All @@ -151,14 +150,14 @@ def generate_enum(self, e: EnumField, indent=0, typename_override = None):

self.write(f"""{prefix}}}\n""", False)

def generate_message(self, message: CompositeField, typename_override = None):
def generate_message(self, message: CompositeField, typename_override=None):
if message.omit():
return

# If override is not specified it is a function that returns itself
# If override is not specified it is a function that returns itself
# This is equivalent to do not override
if typename_override is None:
typename_override = lambda x : x
typename_override = lambda x: x

self.write(f"""
message {typename_override(message.typename)} {{
Expand Down Expand Up @@ -220,6 +219,7 @@ def generate(self, service: Service) -> None:
for message in [f for f in notification_fields if isinstance(f, CompositeField)]:
self.generate_message(message, notification_typename_overrides)


def gather_subfields(field: Field) -> List[Field]:
fields = [field]

Expand All @@ -231,4 +231,3 @@ def gather_subfields(field: Field) -> List[Field]:
fields.extend(gather_subfields(field.itemtype))

return fields

2 changes: 1 addition & 1 deletion contrib/msggen/msggen/gen/grpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def generate(self, service: Service) -> None:
typename = str(notification.typename)
snake_name = camel_to_snake(typename)
response_name = notification_typename_overrides(str(notification.response.typename))
stream_request= f"Stream{typename}Request"
stream_request = f"Stream{typename}Request"
stream_name = f"Subscribe{notification.typename}Stream"
self.write(f"""
Expand Down
6 changes: 3 additions & 3 deletions contrib/msggen/msggen/gen/grpc/unconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def generate(self, service: Service):
# TODO Temporarily disabled since the use of overrides is lossy
# self.generate_responses(service)

def generate_composite(self, prefix, field: CompositeField, override = None) -> None:
def generate_composite(self, prefix, field: CompositeField, override=None) -> None:
# First pass: generate any sub-fields before we generate the
# top-level field itself.
if field.omit():
return

if override is None:
override = lambda x : x
override = lambda x: x

for f in field.fields:
if isinstance(f, ArrayField):
Expand Down
1 change: 0 additions & 1 deletion contrib/msggen/msggen/gen/grpc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def notification_typename_overrides(typename: str):
else:
return_class = str


if str(typename).startswith("Connect"):
return return_class(f"Peer{typename}")
else:
Expand Down

0 comments on commit 72a2d5e

Please sign in to comment.