This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author iritkatriel
Recipients Claudiu.Popa, Kevin Shweh, eric.smith, falsetru, iritkatriel, levkivskyi
Date 2020-10-18.23:48:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1603064886.16.0.126088900536.issue38947@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2020-10-18 23:48:06iritkatrielsetrecipients: + iritkatriel, falsetru, eric.smith, Claudiu.Popa, levkivskyi, Kevin Shweh
2020-10-18 23:48:06iritkatrielsetmessageid: <1603064886.16.0.126088900536.issue38947@roundup.psfhosted.org>
2020-10-18 23:48:06iritkatriellinkissue38947 messages
2020-10-18 23:48:05iritkatrielcreate