From 85b0addca40a19f23cdeddc1d1ac6509aefae62a Mon Sep 17 00:00:00 2001 From: PrettyWood Date: Tue, 9 Jun 2020 10:26:19 +0200 Subject: [PATCH] fix: type hints on BaseConfig closes #1614 --- changes/1614-PrettyWood.md | 1 + pydantic/main.py | 4 ++++ tests/test_main.py | 9 ++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changes/1614-PrettyWood.md diff --git a/changes/1614-PrettyWood.md b/changes/1614-PrettyWood.md new file mode 100644 index 0000000000..046a20ec06 --- /dev/null +++ b/changes/1614-PrettyWood.md @@ -0,0 +1 @@ +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 bb01d2e3cc..e47f7af322 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 76e05b70ad..ed28a5ec4f 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__)