Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Ensure that Optional[list] values work correctly with callbacks #1018

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
fix list convertor properly
svlandeg committed Dec 26, 2024

Verified

This commit was signed with the committer’s verified signature.
alexsnaps Alex Snaps
commit 7d7ae7acf5f041707542fbfeca244ecbb3b7f6da
4 changes: 2 additions & 2 deletions typer/main.py
Original file line number Diff line number Diff line change
@@ -642,8 +642,8 @@ def generate_list_convertor(
convertor: Optional[Callable[[Any], Any]], default_value: Optional[Any]
) -> Callable[[Optional[Sequence[Any]]], Optional[List[Any]]]:
def internal_convertor(value: Optional[Sequence[Any]]) -> Optional[List[Any]]:
if default_value is None and (value is None or len(value) == 0):
return None
if value is None or len(value) == 0:
return default_value
return [convertor(v) if convertor else v for v in value]

return internal_convertor