[issue18474] Lambda assigned to object does not automatically get self
New submission from James Lu: if you assign a lambda to a object and call it,you get this: Traceback (most recent call last): File pyshell#21, line 1, in module n.__div__(3) TypeError: lambda() takes exactly 2 arguments (1 given) The full test is here: n = num() n.__div__ function lambda at 0x040B2DF0 n/3 Traceback (most recent call last): File pyshell#20, line 1, in module n/3 TypeError: unsupported operand type(s) for /: 'num' and 'int' n.__div__(3) Traceback (most recent call last): File pyshell#21, line 1, in module n.__div__(3) TypeError: lambda() takes exactly 2 arguments (1 given) -- messages: 193166 nosy: James.Lu priority: normal severity: normal status: open title: Lambda assigned to object does not automatically get self ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18474 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18474] Lambda assigned to object does not automatically get self
Changes by James Lu jam...@gmail.com: -- type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18474 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18474] Lambda assigned to object does not automatically get self
Brett Cannon added the comment: What version of Python is this and did you assign the lambda to an instance or class (and if this is Python 2, new-style or classic class)? -- nosy: +brett.cannon ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18474 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18474] Lambda assigned to object does not automatically get self
James Lu added the comment: 2.5,new-style -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18474 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18474] Lambda assigned to object does not automatically get self
James Lu added the comment: instance,assinged during __init__ -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18474 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18474] Lambda assigned to object does not automatically get self
James Lu added the comment: Also,there were some bugs, but after I fixed them, it would only work if I did this: n.__div__(n,3) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18474 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18474] Lambda assigned to object does not automatically get self
Eric V. Smith added the comment: Could you provide an entire example, showing the class num and how you assign __div__? -- nosy: +eric.smith ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18474 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18474] Lambda assigned to object does not automatically get self
Amaury Forgeot d'Arc added the comment: This is expected. When you assign to n.__div__ a function which takes two parameters, you have to call it with two parameters: aFunction = lambda x, y: (x, y) n.__div__ = aFunction aFunction(1, 2) n.__div__(1, 2) After all, aFunction and n.__div__ are the same object. Now, it would be different if you had attached the function to the *class* instead: n.__class__.__div__ = aFunction n.__div__(2) # returns (n, 2) In this second example, n.__div__ is a bound method; the first parameter (usually named self) is already filled, and only the second one is required. -- nosy: +amaury.forgeotdarc resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18474 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com