diff --git a/changes/4375-hramezani.md b/changes/4375-hramezani.md new file mode 100644 index 0000000000..fdd836cfae --- /dev/null +++ b/changes/4375-hramezani.md @@ -0,0 +1 @@ +Add support for bare `type` diff --git a/pydantic/typing.py b/pydantic/typing.py index 763a3aac83..bebddb730e 100644 --- a/pydantic/typing.py +++ b/pydantic/typing.py @@ -568,6 +568,9 @@ def get_class(type_: Type[Any]) -> Union[None, bool, Type[Any]]: Tries to get the class of a Type[T] annotation. Returns True if Type is used without brackets. Otherwise returns None. """ + if type_ is type: + return True + if get_origin(type_) is None: return None diff --git a/tests/test_main.py b/tests/test_main.py index 9fbc0b98ca..ecc4734b9a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -981,18 +981,20 @@ class ArbitraryClassAllowedModel(BaseModel): ] -def test_bare_type_type_validation_success(): +@pytest.mark.parametrize('bare_type', [type, Type]) +def test_bare_type_type_validation_success(bare_type): class ArbitraryClassAllowedModel(BaseModel): - t: Type + t: bare_type arbitrary_type_class = ArbitraryType m = ArbitraryClassAllowedModel(t=arbitrary_type_class) assert m.t == arbitrary_type_class -def test_bare_type_type_validation_fails(): +@pytest.mark.parametrize('bare_type', [type, Type]) +def test_bare_type_type_validation_fails(bare_type): class ArbitraryClassAllowedModel(BaseModel): - t: Type + t: bare_type arbitrary_type = ArbitraryType() with pytest.raises(ValidationError) as exc_info: