-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Bug report
Bug description:
class X:
# HARD to define a pure lambda function in class
fn_a = lambda x: x
def test(self):
print(f'{type(self.fn_a)=}') # type(self.fn_a)=<class 'method'>
assert self.fn_a() == self # OK
# assert self.fn_a(1) == 1 # ERROR: TypeError: X.<lambda>() takes 1 positional argument but 2 were given
@classmethod
def cls_test(cls):
print(f'{type(cls.fn_a)=}') # type(cls.fn_a)=<class 'function'>
assert cls.fn_a(1) == 1 # OK
x = X()
x.cls_test()
x.test()
print(f'{X.fn_a=}') # X.fn_a=<function X.<lambda> at 0x103086b60>
It is very HARD to define a pure lambda function in class, the result is unexpected.
I’m not sure if it was intentionally designed this way or if I missed something.
CPython versions tested on:
3.12
Operating systems tested on:
macOS
### Tasks