Skip to content

HasProperties __init__ allows overriding class attributes #288

@fwkoch

Description

@fwkoch

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 -

if not prop and not hasattr(self, key):
- it overrides the attribute -
setattr(self, key, val)
If the kwarg is neither a property nor an existing attribute, __init__ raises an AttributeError -
raise AttributeError(

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions