Skip to content

Commit 2486aae

Browse files
committed
Restructure transport.lookup to avoid spurious mypy error
lookup() accepts None also, because it is intended to return the default. dict.get() obviously accepts None, because it will not be present and thus return the default. Apparently mypy wants to be stricter than that. Just restructure to be a bit plainer.
1 parent 924db0a commit 2486aae

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/workflows/transport/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
default_transport = "PikaTransport"
1212

1313

14-
def lookup(transport: str) -> type[CommonTransport]:
14+
def lookup(transport: str | None) -> type[CommonTransport]:
1515
"""Get a transport layer class based on its name."""
16-
return get_known_transports().get(
17-
transport, get_known_transports()[default_transport]
18-
)
16+
known_transports = get_known_transports()
17+
if transport not in known_transports:
18+
return known_transports[default_transport]
19+
return known_transports[transport]
1920

2021

2122
def add_command_line_options(

0 commit comments

Comments
 (0)