Skip to content

Variable length tuples not working in 1.8.0 #2416

@tlambert03

Description

@tlambert03

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']

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions