Currently, Neo class constructors use **kwargs
for both recommended attributes (name
, file_origin
, etc.) and for optional annotations.
For me, **kwargs
should only be used when we do not know in advance what the argument names will be, which is not the case here. Used otherwise, it is a very good way to hide useful information from the user.
I propose that all recommended attributes are listed explicitly in the argument list to each class' __init__
method. These arguments can then be passed onto the BaseNeo
constructor, which handles assigning the arguments to attributes.
e.g.
{{{
!python
class SomeClass(BaseNeo):
def __init__(self, req_arg1, req_arg2, name=None, file_origin=None, file_datetime=None, **annotations):
BaseNeo.__init__(name=name, file_origin=file_origin, file_datetime=file_datetime, **annotations)
class BaseNeo(object):
def __init__(self, name=None, file_origin=None, file_datetime=None, **annotations):
self.name = name
self.file_origin = file_origin
self.file_datetime = file_datetime
self.annotations = annotations
}}}
This way, the implementation is centralised in BaseNeo
, but the interface definition is explicit in every class. I agree this is a little more work (although mostly copy-and-paste), but I think it is worth it for increasing code clarity and making a clear distinction between recommended attributes and user-defined annotations. In any case, if we add, delete or change a common attribute, we already have to change the documentation for every derived class, so why not change the argument list at the same time?
Imported from Trac ticket:32
Opened: 2011-09-27 13:43:46
Last modified: 2011-09-28 14:52:03
Component: core
Priority: major
Owner: somebody
Reporter: apdavison