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

Variable length tuples not working in 1.8.0 #2416

Closed
3 tasks done
tlambert03 opened this issue Feb 26, 2021 · 1 comment · Fixed by #2421
Closed
3 tasks done

Variable length tuples not working in 1.8.0 #2416

tlambert03 opened this issue Feb 26, 2021 · 1 comment · Fixed by #2421
Labels
bug V1 Bug related to Pydantic V1.X
Milestone

Comments

@tlambert03
Copy link
Contributor

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

It wasn't clear to me from the description of the breaking changes described in 1.8.0 whether it is expected that variable length tuples should now be handled differently, but I'm seeing something similar to #2132 when nesting generics inside of a variable length tuple:

from typing import Tuple
from pydantic import BaseModel

# works
class A(BaseModel):
	t: Tuple[Tuple[int]] = ()

# works
class B(BaseModel):
	t: Tuple[Tuple[int, ...]] = ()

# fails
class C(BaseModel):
	t: Tuple[Tuple[int], ...] = ()
TypeError                                 Traceback (most recent call last)
~/miniconda3/envs/napdev/lib/python3.8/site-packages/pydantic/validators.cpython-38-darwin.so in pydantic.validators.find_validators()

TypeError: issubclass() arg 1 must be a class

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-3-3f541325cc4d> in <module>
----> 1 class C(BaseModel):
      2     t: Tuple[Tuple[int], ...] = ()
      3

~/miniconda3/envs/napdev/lib/python3.8/site-packages/pydantic/main.cpython-38-darwin.so in pydantic.main.ModelMetaclass.__new__()

~/miniconda3/envs/napdev/lib/python3.8/site-packages/pydantic/fields.cpython-38-darwin.so in pydantic.fields.ModelField.infer()

~/miniconda3/envs/napdev/lib/python3.8/site-packages/pydantic/fields.cpython-38-darwin.so in pydantic.fields.ModelField.__init__()

~/miniconda3/envs/napdev/lib/python3.8/site-packages/pydantic/fields.cpython-38-darwin.so in pydantic.fields.ModelField.prepare()

~/miniconda3/envs/napdev/lib/python3.8/site-packages/pydantic/fields.cpython-38-darwin.so in pydantic.fields.ModelField.populate_validators()

~/miniconda3/envs/napdev/lib/python3.8/site-packages/pydantic/validators.cpython-38-darwin.so in find_validators()

RuntimeError: error checking inheritance of typing.Tuple[int] (type: Tuple[int])

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.8
            pydantic compiled: True
                 install path: ~/miniconda3/envs/napdev/lib/python3.8/site-packages/pydantic
               python version: 3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 23:22:12)  [Clang 11.0.1 ]
                     platform: macOS-10.15.7-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions']
@tlambert03 tlambert03 added the bug V1 Bug related to Pydantic V1.X label Feb 26, 2021
@PrettyWood
Copy link
Member

Hi @tlambert03 and thanks for reporting 🙏
Indeed I changed recently the code related to tuple to be more explicit and support () (empty tuple) but missed the case of Ellipsis with compound type as first argument.
I open a PR to fix this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants