seequent / properties

An organizational aid and wrapper for validation and tab completion of class properties/traits.
http://propertiespy.rtfd.org
MIT License
18 stars 9 forks source link

HasProperties __init__ allows overriding class attributes #288

Open fwkoch opened 5 years ago

fwkoch commented 5 years ago

HasProperties.__init__ takes arbitrary key word arguments and assigns them to existing properties. However, it also has a strange behaviour: if the kwarg is not a property but is an existing attribute - https://github.com/seequent/properties/blob/6daa40a5bfdc58a14b707ab4bd8cc0b733a82781/properties/base/base.py#L313 - it overrides the attribute - https://github.com/seequent/properties/blob/6daa40a5bfdc58a14b707ab4bd8cc0b733a82781/properties/base/base.py#L324 If the kwarg is neither a property nor an existing attribute, __init__ raises an AttributeError - https://github.com/seequent/properties/blob/6daa40a5bfdc58a14b707ab4bd8cc0b733a82781/properties/base/base.py#L314

For example, this errors:

class MyClass(properties.HasProperties):
    pass

MyClass(some_function=0)

But this doesn't...

class MyClass(properties.HasProperties):

    def some_function(self):
        ...

MyClass(some_function=0)

This isn't a huge deal; I mean, you can override any attribute once the object is created. It's just super strange that __init__ allows this implicitly.