Bug report
functools.update_wrapper silently remove dataclass function wrapper copies all attributes from wrapped callable to wrapper, which can lead to surprising behavior. In this case the fun attribute is copied, totally changing the behavior of the code:
Repro:
import dataclasses
import functools
from typing import Any, Callable
@dataclasses.dataclass()
class PlusOne:
fun: Callable[..., int]
def __post_init__(self):
functools.update_wrapper(self, self.fun)
def __call__(self, *args, **kwargs):
return self.fun(*args, **kwargs) + 1
def identity(x):
return x
print(PlusOne(identity)(0)) # 1
print(PlusOne(PlusOne(identity))(0)) # 1
Removing __post_init__ fixes the issue.
Your environment
Linux, 3.10.11