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

Improve typing of settings and add plugin settings object #1833

Merged

Conversation

dbluhm
Copy link
Contributor

@dbluhm dbluhm commented Jun 22, 2022

This PR implements some minor improvements on the type hints for the Settings classes and adds a class for PluginSettings. While working with plugins with configuration stored in ACA-Py's settings object, we often find ourselves needing to write lines like the following:

value = cast(dict, context.settings.get(
    "plugin_config", {}
)).get(
    "my_plugin", {}
).get("value", DEFAULT_VALUE)

With this PR, we can now use:

value = context.settings.for_plugin("my_plugin").get("value", DEFAULT_VALUE)

Or

settings = context.settings.for_plugin("my_plugin")
value = settings.get("value", DEFAULT_VALUE)

The plugin settings object is immutable. This decision was made to encourage plugin authors to handle mutable values through either objects injected into the context on startup or by storing values in a record.

It's a minor quality of life tweak but this adds more structure to plugin configuration and value retrieval that I think was previously lacking while also improving readability.

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@814cd8d). Click here to learn what that means.
The diff coverage is 88.46%.

@@           Coverage Diff           @@
##             main    #1833   +/-   ##
=======================================
  Coverage        ?   93.72%           
=======================================
  Files           ?      536           
  Lines           ?    34012           
  Branches        ?        0           
=======================================
  Hits            ?    31878           
  Misses          ?     2134           
  Partials        ?        0           

@swcurran swcurran merged commit 544ec3a into openwallet-foundation:main Jun 22, 2022
@dbluhm dbluhm deleted the feature/improve-settings-types branch September 17, 2022 14:36
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 this pull request may close these issues.

5 participants