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

Private settings #98

Open
paduszyk opened this issue Sep 3, 2024 · 3 comments
Open

Private settings #98

paduszyk opened this issue Sep 3, 2024 · 3 comments

Comments

@paduszyk
Copy link
Contributor

paduszyk commented Sep 3, 2024

Hi 👋🏻

I'd to share an idea for private settings, a new feature for the django-appconf.

Consider the following example:

class MyAppConf(AppConf):
    PUBLIC = ...
    
    _PRIVATE = ...

    class Meta:
        prefix = "my_app"

In the current implementation, PUBLIC and _PRIVATE are accessible fromdjango.conf.settings via MY_APP_PUBLIC, whereas MY_APP__PRIVATE. My idea is to make _PRIVATE inaccessible as it is considered to be private.

I see two ways we could implement this.

  1. Treat names prefixed with an underscore as private (as in the example above; this is Python's way...). However, the issue with this approach is that some linters may complain that other parts of the codebase use private attributes (e.g. Ruff, the rule SLF001).
  2. Add an extra attribute to Meta (private, let us say) that could be a list of names for private settings.
class MyAppConf(AppConf):
    PUBLIC = ...
    
    PRIVATE = ...

    class Meta:
        prefix = "my_app"
        private = ["private"]  # uppercase is implicit

This could be useful (and elegant/Pythonic IMHO) for adding configurations specific to the configured app. What's your opinion?

If you find this idea interesting, I can open a PR.

@carltongibson
Copy link
Contributor

Hi @paduszyk. Django settings doesn't really have any concept of private settings. AppConf already scopes settings to a particular app, but I'm not sure going further than that is really in scope here.

@paduszyk
Copy link
Contributor Author

paduszyk commented Sep 4, 2024

@carltongibson OK 👍🏻 Maybe the name "private settings" is misleading... By private I meant "seen" only by the AppConf instance. You can access them from myapp.conf.settings, but not from django.conf.settings.

@carltongibson
Copy link
Contributor

But why not just regular attributes in that case?

I'm not really seeing how the need here ties in with AppConf's role as providing scoped Django settings, which are globals essentially.

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

2 participants