8000 Failed to generate schema with typing.Any · Issue #237 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

Failed to generate schema with typing.Any #237

@Gr1N

Description

@Gr1N

Hi,

Found issue with schema generation. Please look at example below:

Python 3.6.5 (default, Mar 30 2018, 06:41:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from pydantic import BaseModel

In [2]: from typing import Dict, Any

In [3]: class Model(BaseModel):
   ...:     foo: Dict[str, Any]
   ...:

In [4]: Model.schema()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-c6adfc7bfbde> in <module>()
----> 1 Model.schema()

~/Projects/Python/pydantic/pydantic/main.py in schema(cls, by_alias)
    297             s['description'] = clean_docstring(cls.__doc__)
    298
--> 299         s.update(cls.type_schema(by_alias))
    300         cls._schema_cache[by_alias] = s
    301         return s

~/Projects/Python/pydantic/pydantic/main.py in type_schema(cls, by_alias)
    283             'properties': (
    284                 {f.alias: f.schema(by_alias) for f in cls.__fields__.values()}
--> 285                 if by_alias else
    286                 {k: f.schema(by_alias) for k, f in cls.__fields__.items()}
    287             )

~/Projects/Python/pydantic/pydantic/main.py in <dictcomp>(.0)
    282             'type': 'object',
    283             'properties': (
--> 284                 {f.alias: f.schema(by_alias) for f in cls.__fields__.values()}
    285                 if by_alias else
    286                 {k: f.schema(by_alias) for k, f in cls.__fields__.items()}

~/Projects/Python/pydantic/pydantic/fields.py in schema(self, by_alias)
    146         s.update(self._schema.extra)
    147
--> 148         ts = self.type_schema(by_alias)
    149         s.update(ts if isinstance(ts, dict) else {'type': ts})
    150         return s

~/Projects/Python/pydantic/pydantic/fields.py in type_schema(self, by_alias)
    164             return {
    165                 'type': 'mapping',
--> 166                 'item_type': self._singleton_schema(by_alias),
    167                 'key_type': self.key_field.type_schema(by_alias)
    168             }

~/Projects/Python/pydantic/pydantic/fields.py in _singleton_schema(self, by_alias)
    185                     'types': [sf.type_schema(by_alias) for sf in self.sub_fields]
    186                 }
--> 187         elif issubclass(self.type_, Enum):
    188             choice_names = self._schema.choice_names or {}
    189             return {

TypeError: issubclass() arg 1 must be a class

In [5]:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0