Promoting Python

Ian Kelly ian.g.kelly at gmail.com
Thu Apr 7 02:56:18 EDT 2016


On Thu, Apr 7, 2016 at 12:30 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Or:
>
>    When a class attribute reference (for class C, say) would yield a
>    class method object, it is transformed into an instance method object
>    whose __self__ attributes is C.
>    <URL: https://docs.python.org/3/reference/datamodel.html?highlight=__g
>    etattr__#the-standard-type-hierarchy>
>
> So the only difference between a regular function and an instance method
> object is the fact that the latter has a __self__ attribute set.
>
> Although even that small difference can be paved over:
>
>     def g():
>         print("g")
>     g.__self__ = a
>     a.f = g

What is this example supposed to accomplish?  Functions don't merely
not have a __self__ attribute set. The __self__ attribute has no
meaning on a function.

Let's take a different example.


class Dialog(Window):

    def __init__(self, parent, title, ok_callback):
        super().__init__(parent, title)
        self._ok_callback = ok_callback
        self._ok_button = Button(self, 'Ok')
        self._ok_button.bind(self._ok_callback)

def f(event):
    print("Hello world")

dialog = Dialog(None, "Example", f)
dialog.show()


Are you suggesting that dialog._ok_callback should be considered a
method of Dialog, despite the fact that the implementation of Dialog
and the implementation of f are entirely unrelated? If so, then I
think that most OOP practitioners would disagree with you.



More information about the Python-list mailing list