Irit Katriel <iritkatr...@yahoo.com> added the comment:

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

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38947>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to