8000 deprecate case_insensitive on BaseSettings config (#885) · ag-python/pydantic@d381fe8 · GitHub
[go: up one dir, main page]

Skip to content

Commit d381fe8

Browse files
authored
deprecate case_insensitive on BaseSettings config (pydantic#885)
1 parent d0c6ec7 commit d381fe8

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

changes/885-samuelcolvin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deprecation warning for `case_insensitive` on `BaseSettings` config

pydantic/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ def prepare_config(config: Type[BaseConfig], cls_name: str) -> None:
118118
)
119119
config.allow_population_by_field_name = config.allow_population_by_alias # type: ignore
120120

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

122130
def is_valid_field(name: str) -> bool:
123131
if not name.startswith('_'):

tests/test_settings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,22 @@ class Config:
252252
assert exc_info.value.errors() == [{'loc': ('foo',), 'msg': 'field required', 'type': 'value_error.missing'}]
253253

254254

255+
def test_case_insensitive(monkeypatch):
256+
class Settings1(BaseSettings):
257+
foo: str
258+
259+
with pytest.warns(DeprecationWarning, match='Settings2: "case_insensitive" is deprecated on BaseSettings'):
260+
261+
class Settings2(BaseSettings):
262+
foo: str
263+
264+
class Config:
265+
case_insensitive = False
266+
267+
assert Settings1.__config__.case_sensitive is False
268+
assert Settings2.__config__.case_sensitive is True
269+
270+
255271
def test_nested_dataclass(env):
256272
@dataclasses.dataclass
257273
class MyDataclass:

0 commit comments

Comments
 (0)
0