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

Allow annotations to define settings #60

Open
ziima opened this issue Dec 2, 2019 · 4 comments
Open

Allow annotations to define settings #60

ziima opened this issue Dec 2, 2019 · 4 comments

Comments

@ziima
Copy link
Collaborator

ziima commented Dec 2, 2019

Since Settings are basically smart dataclass, we might use annotations in settings definition to allow even simpler setup.

The goal would be

class MySettings(AppSettings):
    my_foo: str = Setting(default='my_default')
    my_bar: int = Setting(required=True)

or even yet simpler version

class MySettings(AppSettings):
    my_foo: str = None
    my_bar: int

What do you think?

@pawamoy
Copy link
Owner

pawamoy commented Dec 2, 2019

You mean

class MySettings(AppSettings):
    my_foo: str = "my_default"
    my_bar: int

?

Well yeah, that would be great 😄 !

We would just need to make sure that every feature (setting) of the app can be translated using type annotations. Then refactor 🙂

Not sure what would validators become though 😕

@stinovlas
Copy link
Collaborator

While this can work for the simple type settings, I can't imagine any sensible syntax for nested settings.

I believe that current notation is succinct enough for all practical intents and purposes. However, I wouldn't mind adding this notation as an alternative as long as I still have access to StringSetting et al.

@ziima
Copy link
Collaborator Author

ziima commented Dec 2, 2019

As a middle step, I would propose to translate current Setting to accept annotation-style type argument to check the value against, i.e. add type argument (find better name if possible) and use it to replace TypeValidators.

The problem I was recently facing, was enabling None value in StringSetting. This would help this and most likely other issues.

@pawamoy
Copy link
Owner

pawamoy commented Dec 3, 2019

I'm looking again at pydantic: https://pydantic-docs.helpmanual.io/usage/settings/ and https://pydantic-docs.helpmanual.io/usage/validators/. I think you'll find it interesting as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants