-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Allow class_path
to be a classmethod.
#309
Comments
Welcome and thank you for the proposal! Apart from the sub-classing alternative you mentioned, note that there is also class_from_function. With just one line you can get a class that has as Directly supporting class methods could be added. But, since there is the simple previously mentioned alternative, this is not a high priority. Also, if support for this is implemented, very likely it will not be using |
Thank you for your reply! I thought about using parser = ArgumentParser()
dynamic_class = class_from_function(instantiate_myclass)
parser.add_class_arguments(dynamic_class, "myclass") However, I don't know how to apply it to parser = ArgumentParser()
parser.add_class_arguments(MyClass, "myclass")
# how to use class_from_function with Calendar? so that I can use |
I tried it, and actually it doesn't work. What I had in mind was: CalendarFromStr = class_from_function(Calendar.from_str, Calendar) And in the config: myclass:
calendar:
class_path: __main__.CalendarFromStr However, this fails with:
I will think about how to fix this. |
With pull request #315 what I had in mind would be possible. Please try it out. The use of class_from_function(Calendar.from_str, Calendar, name="CalendarFromStr") |
It works. Thank you very much for the fix! |
🚀 Feature request
Allow
class_path
to be a classmethod.Motivation
It is common to use a classmethod as an alternative way to create new instances:
Then config file would look as follows:
Pitch
A hacky way I tried to make this work is by adding the following to
typehints.py
file:Alternatives
Subclassing to allow alternative initialization:
The text was updated successfully, but these errors were encountered: