Skip to content

Commit

Permalink
deprecate case_insensitive on BaseSettings config (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Oct 11, 2019
1 parent d0c6ec7 commit d381fe8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/885-samuelcolvin.md
@@ -0,0 +1 @@
deprecation warning for `case_insensitive` on `BaseSettings` config
8 changes: 8 additions & 0 deletions pydantic/main.py
Expand Up @@ -118,6 +118,14 @@ def prepare_config(config: Type[BaseConfig], cls_name: str) -> None:
)
config.allow_population_by_field_name = config.allow_population_by_alias # type: ignore

if hasattr(config, 'case_insensitive') and any('BaseSettings.Config' in c.__qualname__ for c in config.__mro__):
warnings.warn(
f'{cls_name}: "case_insensitive" is deprecated on BaseSettings config and replaced by '
f'"case_sensitive" (default False)',
DeprecationWarning,
)
config.case_sensitive = not config.case_insensitive # type: ignore


def is_valid_field(name: str) -> bool:
if not name.startswith('_'):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_settings.py
Expand Up @@ -252,6 +252,22 @@ class Config:
assert exc_info.value.errors() == [{'loc': ('foo',), 'msg': 'field required', 'type': 'value_error.missing'}]


def test_case_insensitive(monkeypatch):
class Settings1(BaseSettings):
foo: str

with pytest.warns(DeprecationWarning, match='Settings2: "case_insensitive" is deprecated on BaseSettings'):

class Settings2(BaseSettings):
foo: str

class Config:
case_insensitive = False

assert Settings1.__config__.case_sensitive is False
assert Settings2.__config__.case_sensitive is True


def test_nested_dataclass(env):
@dataclasses.dataclass
class MyDataclass:
Expand Down

0 comments on commit d381fe8

Please sign in to comment.