Open Erotemic opened 3 years ago
Thanks for the suggestion! With time, this might be something to look into. The name is a bit misleading though: __getinitargs__
is mainly used to find field names that matter, e.g. for __eq__
comparison and hashing. If I were starting the library today, I'd probably rely on dataclasses
mechanisms for most of this.
I was playing with the library, and I noticed that expressions seem to require these boilerplate
__getinitargs__
andinit_arg_names
methods. Given that this is Python 3.6+ it should be easy to automate that via introspection. Here is a proof of concpet:Now classes that inherit from
AutoInspectable
will introspect their__init__
functions and as long a there are no*args
**kwargs
and all arguments have instance attributes with the same name, it provides a function to return an "initkw" dictionary (i.e. keyword arguments that you could pass to the class to construct a new instance).There are edge cases where this doesn't work. Namely *args, **kwargs, and when the instance doesn't exactly register the constructor arguments with the same names, but in those cases it raises a
NotImplementedError
indicating that the user can fill these out manually.Just thought I'd throw that out there.