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

Support variadic generics #5804

Open
dmontagu opened this issue May 19, 2023 · 3 comments
Open

Support variadic generics #5804

dmontagu opened this issue May 19, 2023 · 3 comments

Comments

@dmontagu
Copy link
Contributor

We eventually want to support variadic generics.

There are already some tests for the desired behavior (thanks @caniko).

I'm creating this issue for tracking purposes as I have closed #5351.

@caniko
Copy link
Contributor

caniko commented Jul 26, 2023

Any news on this front?

@dmontagu
Copy link
Contributor Author

dmontagu commented Aug 2, 2023

Working on it now. I think there may be some issues with the existing xfailing tests for this stuff, and it's a bit more complicated than I expected, but making progress..

@dmontagu
Copy link
Contributor Author

dmontagu commented Aug 2, 2023

I think we'll need to modify pydantic-core to support a tuple schema with a variable-length item in the "middle"; right now, I believe the tuple-positional schema only supports variable-number of "tail" items, but in https://peps.python.org/pep-0646/ it is clearly supported to have any number of specific parameters at the start and/or end of the tuple.

I would propose that we actually unify the tuple-positional and tuple-variable schemas, with a schema roughly along the lines of:

class TupleSchema(TypedDict, total=False):
    type: Required[Literal['tuple']]
    leading_items_schema: List[CoreSchema]
    trailing_items_schema: List[CoreSchema]
    variadic_schema: CoreSchema
    min_variadic_length: int
    max_variadic_length: int
    strict: bool
    ref: str
    metadata: Any
    serialization: IncExSeqOrElseSerSchema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants