Skip to content

Commit

Permalink
Walrusify the code (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Apr 12, 2024
1 parent 7ce2a64 commit 6879d6e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/cleo/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ def get_namespaces(self) -> list[str]:
return namespaces

def find_namespace(self, namespace: str) -> str:
all_namespaces = self.get_namespaces()

if namespace not in all_namespaces:
if namespace not in (all_namespaces := self.get_namespaces()):
raise CleoNamespaceNotFoundError(namespace, all_namespaces)

return namespace
Expand Down
7 changes: 2 additions & 5 deletions src/cleo/descriptors/text_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ def _describe_application(self, application: Application, **options: Any) -> Non
described_namespace = options.get("namespace")
description = ApplicationDescription(application, namespace=described_namespace)

help_text = application.help
if help_text:
if help_text := application.help:
self._write(f"{help_text}\n\n")

self._write("<b>Usage:</b>\n")
Expand Down Expand Up @@ -271,9 +270,7 @@ def _get_column_width(self, commands: Sequence[Command | str]) -> int:
return max(widths) + 2

def _get_command_aliases_text(self, command: Command) -> str:
aliases = command.aliases

if aliases:
if aliases := command.aliases:
return f"[{ '|'.join(aliases) }] "

return ""
4 changes: 1 addition & 3 deletions src/cleo/events/event_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def dispatch(self, event: Event, event_name: str | None = None) -> Event:
if event_name is None:
event_name = type(event).__name__

listeners = cast("list[Listener]", self.get_listeners(event_name))

if listeners:
if listeners := cast("list[Listener]", self.get_listeners(event_name)):
self._do_dispatch(listeners, event_name, event)

return event
Expand Down
3 changes: 1 addition & 2 deletions src/cleo/ui/exception_trace/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ def ignore_files_in(self, ignore: str) -> ExceptionTrace:

def render(self, io: IO | Output, simple: bool = False) -> None:
# If simple rendering wouldn't show anything useful, abandon it.
simple_string = str(self._exception) if simple else ""
if simple_string:
if simple_string := str(self._exception) if simple else "":
io.write_line("")
io.write_line(f"<error>{simple_string}</error>")
else:
Expand Down

0 comments on commit 6879d6e

Please sign in to comment.