Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

🐛 command can now accept Optional[T] as a type #480

Merged
merged 2 commits into from
Jun 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pincer/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ async def test_command(
# to implement it.
argument_type = annotation.__origin__

# check if None to keep the type checker happy that its Any
if argument_type is not None and hasattr(argument_type, "__args__"):
# this is a Union, hopefully an Optional/Union[T, None]
# Optional[T] is an alias to Union[T, None]
args = argument_type.__args__

if len(args) != 2 or args[1] != type(None):
raise InvalidArgumentAnnotation(
"`Union` is not a supported option type"
)

argument_type = args[0]

if not argument_type:
if annotation in _options_type_link:
options.append(
Expand Down