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

Provide immutable config objects #3

Closed
joerunde opened this issue Apr 20, 2023 · 0 comments · Fixed by #4
Closed

Provide immutable config objects #3

joerunde opened this issue Apr 20, 2023 · 0 comments · Fixed by #4

Comments

@joerunde
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Currently all aconfig.Config objects are mutable.
When I have a config object that I want to distribute across an application, my choices are either:

  • Trust that developers never write code that modifies this config object, or
  • Hand out a full copy of my config so that any code accessing it is guaranteed not to muck with anything if it makes changes to the config

Neither of these choices are all that great.

Describe the solution you'd like

If a config can be created with an option to be immutable, such as:

mutable_config = aconfig.Config({1: 2, 3: 4})
immutable_config = aconfig.Config(mutable_config, frozen=True)

Then I can pass around the immutable_config to any piece of code that wants it without worry, or expensive copying

This can probably be implemented by swapping MappingProxys in the guts of the config code instead of plain dicts

Describe alternatives you've considered

Not implementing this and crying?

Could maybe slap some code in __setattr__ that checks if the thing is supposed to be immutable and stops any mutations.
That sounds a little less robust than the proxies which have no __setattr__ at all.

Additional context

Add any other context about the feature request here.

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

Successfully merging a pull request may close this issue.

1 participant