Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type hints on BaseConfig #1618

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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__)