data attributes override method attributes?

Chris Angelico rosuav at gmail.com
Tue Sep 25 11:03:12 EDT 2012


On Wed, Sep 26, 2012 at 12:54 AM, Peter Otten <__peter__ at web.de> wrote:
> To me
>
> "Data attributes override method attributes with the same name"
>
> implies that data attributes take precedence over method attributes, not
> that they replace them only when there is an assignment of data after the
> method definition.
>
> I would even consider replacing the whole paragraph
> with something like
>
> "Data attributes and method attributes share the same namespace. To avoid
> name conflicts consider using verbs for methods and nouns for data
> attributes"

Instance attributes override (shadow) class attributes. Since methods
tend to be on the class and data tends to be on the instance, the
original sentence does make some sense. The section is talking about
conventions, so it's not inherently wrong, but perhaps just needs a
comment about methods not usually being attached to the instance.

ChrisA



More information about the Python-list mailing list