[Feature] Support for Sequence type #1214
leandrocm86
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Why annotate with Sequence? It's good design for lists we don't intend to modify. The implementation would be very simple (probably 1 line of code), because we could process the type just as we do with List (thus actually creating a list, which is one of the concrete types of Sequence). But the python linter would error if we tried to modify that list, since it wouldn't know the concrete type that was instantiated.
Alternative: Tuple is also useful for immutable lists, but while tuple is supported by Typer when it has a known (fixed) length, it is not supported for ellipsis (ex: tuple[str, ...]). Support for that would also be welcomed, but I suppose there would be slightly more lines of code to add.
PS: Click even creates tuples by default whenever we use nargs. With Click, if we type annotate such argument as list, we have a runtime error when trying to modify it.
Beta Was this translation helpful? Give feedback.
All reactions