Skip to content

AboutClassAttributes: Order of definition matters#249

@programmer-ke

Description

@programmer-ke

Thanks for this work, I'm discovering nooks and crannies of Python that I wasn't previously aware of.

For the following section, I wanted to point out that what seems to matter is order of definition of the class attributes.

defbark(self):
return"instance bark"
defgrowl(self):
return"instance growl"
@staticmethod
defbark():
return"staticmethod bark, arg: None"
@classmethod
defgrowl(cls):
return"classmethod growl, arg: cls="+cls.__name__

The classmethod and staticmethod are redefining the instance methods. If order of each of bark and growl is flipped, the instance method will redefine the static/class method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions