Re: Python constructors have particular semantics, and ‘Foo.__init__’ doesn't qualify

Ian Kelly ian.g.kelly at gmail.com
Thu Dec 15 14:04:31 EST 2016


On Thu, Dec 15, 2016 at 11:05 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 12/14/2016 11:14 PM, Thomas 'PointedEars' Lahn wrote:
>
>> According to
>> <https://docs.python.org/3/tutorial/classes.html#method-objects>,
>> “Foo.__init__” is _not_ an instance method.  Were it an instance
>> method, the following would not happen:
>
>
> This link points to subsection 9.3.4. Method Objects
>
>> | >>> class Foo:
>> | ...     def __init__ (self):
>> | ...         pass
>> | ...
>> | >>> Foo.__init__.__self__
>> | Traceback (most recent call last):
>> |   File "<stdin>", line 1, in <module>
>> | AttributeError: 'function' object has no attribute '__self__'
>
>
> You have misread the docs.  Foo.__init__ is the function. Foo().__init__ is
> a method object with the attribute __self__.  You omitted the ()s.

I think this is actually the point that Thomas was making. He was
responding to the assertion that "Foo.__init__" is an instance method
and demonstrating that it's false because Foo is the class, not an
instance of Foo.

If I've observed anything about Thomas over the years he's been
posting here, it's that he's extremely literal and will pick apart
tiny irrelevant nuances to the point of being (or at least appearing)
trollish.


More information about the Python-list mailing list