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 in BaseSettings.Config #4450

Merged
merged 2 commits into from Aug 30, 2022
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/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 = ''
samuelcolvin marked this conversation as resolved.
Show resolved Hide resolved
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