Skip to content

Commit

Permalink
fix: type hints on BaseConfig (#1618)
Browse files Browse the repository at this point in the history
closes #1614
  • Loading branch information
PrettyWood committed Jun 9, 2020
1 parent 5e82689 commit 329b1d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/1614-PrettyWood.md
@@ -0,0 +1 @@
Ensure `SchemaExtraCallable` is always defined to get type hints on BaseConfig.
4 changes: 4 additions & 0 deletions pydantic/main.py
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion 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
Expand Down Expand Up @@ -1133,3 +1133,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__)

0 comments on commit 329b1d3

Please sign in to comment.