[New-bugs-announce] [issue36175] Identity of bound methods

Abe Leite report at bugs.python.org
Sun Mar 3 21:42:19 EST 2019


New submission from Abe Leite <abrahamjleite at gmail.com>:

The following code produces unexpected behavior in all versions of Python I have tested.

>>> class a:
...     def method(self): pass

>>> inst = a()
>>> inst.method is inst.method
False

It appears that id(inst.method) changes each time inst.method is accessed by normal means.

So the tuple (id(inst.method), id(inst.method)) will have the same item repeated, but the tuple (id(inst.method), inst.method, id(inst.method)) will not.

Note that for unbound methods and other functions, this issue does not occur.

This creates a transparency issue for bound instance methods taking the place of functions.

My apologies if this is a design decision that has already been resolved! It just seemed like a strange behavior to me.

--Abe

----------
components: Interpreter Core
messages: 337063
nosy: Abe Leite
priority: normal
severity: normal
status: open
title: Identity of bound methods
type: behavior
versions: Python 2.7, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36175>
_______________________________________


More information about the New-bugs-announce mailing list