Skip to content

Commit

Permalink
fix type hints in BaseSettings.Config (#4450)
Browse files Browse the repository at this point in the history
* fix type hints in BaseSettings.Config

* add tests and change notice
  • Loading branch information
samuelcolvin committed Aug 30, 2022
1 parent f8575aa commit b065908
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions changes/4450-samuelcolvin.md
@@ -0,0 +1 @@
Add type hints to `BaseSettings.Config` to avoid mypy errors, also correct mypy version compatibility notice in docs.
4 changes: 2 additions & 2 deletions docs/mypy_plugin.md
Expand Up @@ -90,7 +90,7 @@ To get started, all you need to do is create a `mypy.ini` file with following co
plugins = pydantic.mypy
```

The plugin is compatible with mypy versions 0.910, 0.920, 0.921 and 0.930.
The plugin is compatible with mypy versions `>=0.910`.

See the [mypy usage](usage/mypy.md) and [plugin configuration](#configuring-the-plugin) docs for more details.

Expand Down Expand Up @@ -168,4 +168,4 @@ init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = true
```
```
18 changes: 9 additions & 9 deletions pydantic/env_settings.py
Expand Up @@ -79,15 +79,15 @@ def _build_values(
return {}

class Config(BaseConfig):
env_prefix = ''
env_file = None
env_file_encoding = None
env_nested_delimiter = None
secrets_dir = None
validate_all = True
extra = Extra.forbid
arbitrary_types_allowed = True
case_sensitive = False
env_prefix: str = ''
env_file: Optional[DotenvType] = None
env_file_encoding: Optional[str] = None
env_nested_delimiter: Optional[str] = None
secrets_dir: Optional[StrPath] = None
validate_all: bool = True
extra: Extra = Extra.forbid
arbitrary_types_allowed: bool = True
case_sensitive: bool = False

@classmethod
def prepare_field(cls, field: ModelField) -> None:
Expand Down
7 changes: 7 additions & 0 deletions tests/mypy/modules/settings_config.py
@@ -0,0 +1,7 @@
from pydantic import BaseSettings


class Settings(BaseSettings):
class Config(BaseSettings.Config):
env_file = '.env'
env_file_encoding = 'utf-8'
1 change: 1 addition & 0 deletions tests/mypy/test_mypy.py
Expand Up @@ -48,6 +48,7 @@
('pyproject-plugin-strict.toml', 'plugin_success.py', 'plugin-success-strict.txt'),
('pyproject-plugin-strict.toml', 'plugin_fail.py', 'plugin-fail-strict.txt'),
('pyproject-plugin-strict.toml', 'fail_defaults.py', 'fail_defaults.txt'),
('mypy-plugin-strict.ini', 'settings_config.py', None),
]
executable_modules = list({fname[:-3] for _, fname, out_fname in cases if out_fname is None})

Expand Down

0 comments on commit b065908

Please sign in to comment.