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

Enforce Protocol settings at instantiation #405

Open
ianmkenney opened this issue Nov 13, 2024 · 0 comments
Open

Enforce Protocol settings at instantiation #405

ianmkenney opened this issue Nov 13, 2024 · 0 comments
Milestone

Comments

@ianmkenney
Copy link
Contributor

Problem

The Settings provided to a Protocol are never validated at runtime and incorrect settings can be passed to a Protocol only to cause failures during execution. Since most protocols will require custom settings objects, the types of these settings should be confirmed during instantiation of the Protocols themselves, catching failures early.

Solution

We should add a new class attribute _settings_cls: type[Settings] to the Protocol base class. This attribute should be left unbound. In the Protocol's __init__ method, we can perform the following checks:

  1. Check if the _settings_cls attribute has been defined in the class
  2. Check if the provided settings are an instance of the _settings_cls

If either of these checks fail, raise:

  1. NotImplementedError if _settings_cls is not defined
  2. ValueError if the settings provided do not match the expected type

I've implemented a similar pattern in stratocaster to validate custom settings at instantiation. I believe this approach would be beneficial for Protocols.

Additional considerations

Note that this will break backwards compatibility for existing Protocols.

@dotsdl dotsdl added this to the Release 1.3 milestone Nov 26, 2024
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