Skip to content

Tuple field triggers error checking inheritance #2132

@asmodehn

Description

@asmodehn

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

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

             pydantic version: 1.7.2
            pydantic compiled: True
                 install path: /home/alexv/.local/share/virtualenvs/datacrystals-F4r2dbjD/lib/python3.8/site-packages/pydantic
               python version: 3.8.2 (default, Apr 27 2020, 15:53:34)  [GCC 9.3.0]
                     platform: Linux-5.4.0-7634-generic-x86_64-with-glibc2.29
     optional deps. installed: ['typing-extensions']

I didn't yet investigate what is happening here, but this looks like something that should be working...

from pydantic.dataclasses import dataclass
import typing
@dataclass
class wrappingTuple:
    field: typing.Tuple

print(wrappingTuple(field=(0,1))

triggers :

Traceback (most recent call last):
  File "pydantic/validators.py", line 615, in pydantic.validators.find_validators
TypeError: issubclass() arg 1 must be a class
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 2, in <module>
  File "pydantic/dataclasses.py", line 216, in pydantic.dataclasses.dataclass
  File "pydantic/dataclasses.py", line 211, in pydantic.dataclasses.dataclass.wrap
  File "pydantic/dataclasses.py", line 147, in pydantic.dataclasses._process_class
  File "pydantic/main.py", line 925, in pydantic.main.create_model
  File "pydantic/main.py", line 262, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 315, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 284, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 362, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 538, in pydantic.fields.ModelField.populate_validators
  File "pydantic/validators.py", line 624, in find_validators
RuntimeError: error checking inheritance of typing.Tuple (type: Tuple)

However this works fine :

from pydantic.dataclasses import dataclass
import typing
@dataclass
class wrappingTuple:
    field: tuple

print(wrappingTuple(field=(0,1))
wrappingTuple(field=(0, 1))

and this as well :

from pydantic.dataclasses import dataclass
import typing
@dataclass
class wrappingTuple:
    field: typing.List

print(wrappingTuple(field=[0,1])
wrappingTuple(field=[0, 1])

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions