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

Move validation of class enum trait to run time instead of import time #2100

Closed
maxnoe opened this issue Oct 20, 2022 · 2 comments · Fixed by #2102
Closed

Move validation of class enum trait to run time instead of import time #2100

maxnoe opened this issue Oct 20, 2022 · 2 comments · Fixed by #2102

Comments

@maxnoe
Copy link
Member

maxnoe commented Oct 20, 2022

Please describe the use case that requires this feature.

Currently, we define class traitlets like this:

class Foo(Component):
    bar_type = create_class_enum_trait(Bar...).tag(config=True)

this runs at import time of Foo. Which makes it impossible to use subclasses of Bar that are only imported at a later stage.

This is problematic for subclasses defined in other submodules than the base class and the containing component.

THis was triggered by the machine learning module, where ShowerProcessor has a class enum trait of Reconstructor but because ctapipe.ml.sklearn cannot import Reconstructor without also importing ShowerProcessor (as ctapipe.reco.__init__ imports it), the ml reconstructors are not yet defined when the class enum trait is created.

This is even more problematic for the case of plugins.

Describe the solution you'd like

Move the check if a provided string is an available class to the runtime (i.e. the validate method).

@StFroese
Copy link
Member

So this is the reason for this:

# reconstructors must be imported before ShowerProcessor, so
# they are available there

@maxnoe
Copy link
Member Author

maxnoe commented Oct 21, 2022

Exactly

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