diff --git a/changes/1614-PrettyWood.md b/changes/1614-PrettyWood.md new file mode 100644 index 00000000000..b7d06f68105 --- /dev/null +++ b/changes/1614-PrettyWood.md @@ -0,0 +1,2 @@ +Ensure `SchemaExtraCallable` is always defined to get type +hints on BaseConfig. \ No newline at end of file diff --git a/pydantic/main.py b/pydantic/main.py index bb01d2e3cc4..e47f7af3221 100644 --- a/pydantic/main.py +++ b/pydantic/main.py @@ -66,6 +66,10 @@ def __call__(self, schema: Dict[str, Any], model_class: Type['Model']) -> None: pass +else: + SchemaExtraCallable = Callable[..., None] + + try: import cython # type: ignore except ImportError: diff --git a/tests/test_main.py b/tests/test_main.py index 76e05b70ad1..ed28a5ec4f3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,6 +1,6 @@ import sys from enum import Enum -from typing import Any, Callable, ClassVar, Dict, List, Mapping, Optional, Type +from typing import Any, Callable, ClassVar, Dict, List, Mapping, Optional, Type, get_type_hints from uuid import UUID, uuid4 import pytest @@ -1119,3 +1119,10 @@ class Model2(BaseModel): Model1.parse_obj({}) with pytest.raises(ValidationError): Model2.parse_obj({}) + + +def test_base_config_type_hinting(): + class M(BaseModel): + a: int + + get_type_hints(M.__config__)