Message378914
I think you may have meant this issue (which is not related to field()):
from dataclasses import dataclass
from typing import Callable
@dataclass(init=True)
class Foo:
callback: Callable[[int], int] = lambda x: x**2
@dataclass(init=False)
class Bar:
callback: Callable[[int], int] = lambda x: x**2
print('Foo().callback:', Foo().callback)
print('Foo().callback(2):', Foo().callback(2))
print('Bar().callback:', Bar().callback)
print('Bar().callback(3):', Bar().callback(3))
Output:
Foo().callback: <function Foo.<lambda> at 0x019592F8>
Foo().callback(2): 4
Bar().callback: <bound method Bar.<lambda> of Bar(callback=<bound method Bar.<lambda> of ...>)>
Traceback (most recent call last):
File "C:\Users\User\src\cpython\x.py", line 17, in <module>
print('Bar().callback(3):', Bar().callback(3))
TypeError: Bar.<lambda>() takes 1 positional argument but 2 were given |
|
Date |
User |
Action |
Args |
2020-10-18 23:48:06 | iritkatriel | set | recipients:
+ iritkatriel, falsetru, eric.smith, Claudiu.Popa, levkivskyi, Kevin Shweh |
2020-10-18 23:48:06 | iritkatriel | set | messageid: <1603064886.16.0.126088900536.issue38947@roundup.psfhosted.org> |
2020-10-18 23:48:06 | iritkatriel | link | issue38947 messages |
2020-10-18 23:48:05 | iritkatriel | create | |
|