When I create model and using typing.Type annotation, AssertionError gets raised immediately:
from typing import Type, Any
from pydantic import BaseModel
class Model(BaseModel):
obj: Type[Any] # Could be any type there, e. g. Type[str]
```py
Traceback (most recent call last):
class Model(BaseModel):
File "pydantic/main.py", line 209, in pydantic.main.MetaModel.__new__
File "pydantic/fields.py", line 135, in pydantic.fields.Field.infer
File "pydantic/fields.py", line 112, in pydantic.fields.Field.__init__
File "pydantic/fields.py", line 177, in pydantic.fields.Field.prepare
File "pydantic/fields.py", line 238, in pydantic.fields.Field._populate_sub_fields
AssertionError
AssertionError is raised on this line, `origin` is `type` here:
https://github.com/samuelcolvin/pydantic/blob/18d4b2bb2ac9790bd58780dba67947a088725731/pydantic/fields.py#L252
### Upd:
Also just discovered that if we replace `Type[Any]` with `type`, will get this:
```py
Traceback (most recent call last):
class Model(BaseModel):
File "pydantic/main.py", line 209, in pydantic.main.MetaModel.__new__
File "pydantic/fields.py", line 135, in pydantic.fields.Field.infer
File "pydantic/fields.py", line 112, in pydantic.fields.Field.__init__
File "pydantic/fields.py", line 178, in pydantic.fields.Field.prepare
File "pydantic/fields.py", line 269, in pydantic.fields.Field._populate_validators
File "pydantic/validators.py", line 475, in find_validators
RuntimeError: no validator found for <class 'type'>
This can be bypassed by setting Confif.arbitrary_types_allowed to True
I guess Currently this "type" is not supported, PR welcome to implement it.
Maybe also replace bare AssertionError with TypeError(f'Type {origin} is currently not supported')?
yes agreed.
Seems to be fixed by #678
[joke mode on, don't take it too seriously]
@MrMrRobat is this one of those recursion jokes? -> Your comment on a fix (https://github.com/samuelcolvin/pydantic/issues/678#issuecomment-538802546) is linking to the same issue, this one to be exact ;)
[joke mode off]
On a serious note - is the fix in some other place?
Another serious question, what is typing.Type used for? I've not seen that, and instead usually see the bare type, e.g. value: str or value: Any, etc.
well, the same stuff it's used for in the python docs - defining class types, rather than instances.
Most helpful comment
[joke mode on, don't take it too seriously]
@MrMrRobat is this one of those recursion jokes? -> Your comment on a fix (https://github.com/samuelcolvin/pydantic/issues/678#issuecomment-538802546) is linking to the same issue, this one to be exact ;)
[joke mode off]
On a serious note - is the fix in some other place?