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

Tweak sources to have case_sensitive and env_prefix usable as args #76

Merged
merged 7 commits into from
Jun 19, 2023

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Jun 13, 2023

Fixes #74.

Ended up doing a bit of refactoring, the idea is to avoid accessing self.config (even self.settings_cls.model_config in some places, which points to the same config object) in sources, and determine the values to use in _settings_build_values instead.

Alternatively we could have some kind of "context" object, created by merging args values from _settings_build_values and values from the model_config. This way we wouldn't have to pass each config value by hand to the sources' __init__.

Waiting for review before fixing tests and updating documentation.

Selected Reviewer: @hramezani

pydantic_settings/main.py Outdated Show resolved Hide resolved
self.env_prefix_len: int = env_prefix_len
) -> None:
super().__init__(settings_cls, case_sensitive, env_prefix)
self.env_nested_delimiter = env_nested_delimiter
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env_nested_delimiter is str | None here, isn't it an issue regarding this part?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If env_name='foo' then f'{env_name}{self.env_nested_delimiter}' will be converted to 'fooNone' which is not raising an error but it's better to handle it better.
we can return at the beginning of the function by checking the env_nested_delimiter is None.
If you want to fix it, please do it in a separate PR. otherwise I will fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take a look

@Viicos
Copy link
Contributor Author

Viicos commented Jun 14, 2023

Please review

@hramezani
Copy link
Member

@Viicos Thanks for this PR.
The implementation LGTM!

Please continue with the tests and documentation

@hramezani
Copy link
Member

please update

@Viicos
Copy link
Contributor Author

Viicos commented Jun 16, 2023

Basic tests added, updated docstrings and documentation (not sure the added section is required, as each section describing BaseSettings related config options is already describing both behaviors -- model_config vs init args). Waiting for #76 (comment)

@Viicos
Copy link
Contributor Author

Viicos commented Jun 16, 2023

Please review

docs/index.md Outdated Show resolved Hide resolved
@hramezani
Copy link
Member

please update

@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.08 🎉

Comparison is base (dba60fe) 97.32% compared to head (f7309ec) 97.41%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #76      +/-   ##
==========================================
+ Coverage   97.32%   97.41%   +0.08%     
==========================================
  Files           5        5              
  Lines         299      309      +10     
  Branches       67       67              
==========================================
+ Hits          291      301      +10     
  Misses          6        6              
  Partials        2        2              
Impacted Files Coverage Δ
pydantic_settings/main.py 100.00% <100.00%> (ø)
pydantic_settings/sources.py 97.67% <100.00%> (+0.03%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Viicos
Copy link
Contributor Author

Viicos commented Jun 18, 2023

Please review

@hramezani hramezani merged commit b08fa5b into pydantic:main Jun 19, 2023
18 checks passed
@hramezani
Copy link
Member

Thanks @Viicos

@Viicos Viicos deleted the 74-basesettings-args branch June 19, 2023 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add env_prefix to BaseSettings args
3 participants