Pydantic: Serialisation of a type

Created on 28 Mar 2020  路  2Comments  路  Source: samuelcolvin/pydantic

Question

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

             pydantic version: 1.4
            pydantic compiled: True
                 install path: /home/dan/.cache/pypoetry/virtualenvs/pepper2-A7x1WGfC-py3.8/lib/python3.8/site-packages/pydantic
               python version: 3.8.2 (default, Feb 26 2020, 22:21:03)  [GCC 9.2.1 20200130]
                     platform: Linux-5.4.26-1-lts-x86_64-with-glibc2.2.5
     optional deps. installed: ['typing-extensions']

I'm attempting to serialise an object that contains the type of another object.

from typing import Type

import pydantic

class Foo:
    pass

class FirstFoo(Foo):
    pass

class SecondFoo(Foo):
    pass

class MyModel(pydantic.BaseModel):
    foo_type: Type[Foo]

I currently get the error: ValueError: [TypeError("'property' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]

The behaviour that I'm trying to get is a string that represents the class.

question

Most helpful comment

Hi @trickeydan, could you put a working example to actually reproduce the error please ?

All 2 comments

Hi @trickeydan, could you put a working example to actually reproduce the error please ?

Upon further poking, indications point towards an issue in CPython. Closing this issue for now, will reopen if it turns out to be Pydantic.

Was this page helpful?
0 / 5 - 0 ratings