In mypy 0.930 the signature for `object.__reduce__` has been changed to ```python def __reduce__(self) -> str | Tuple[object, ...]: ... ``` This is wrong, reading [the documentation](https://docs.python.org/3/library/pickle.html#object.__reduce__). The following valid code now is reported as error: ```python from typing import Any, Tuple, Union class Diagnostic: def __reduce__(self) -> Union[str, Tuple[Any, ...]]: res = super().__reduce__() if isinstance(res, tuple) and len(res) >= 3: res[2]["_info"] = 42 return res ```
Activity
dvarrazzo commentedon Dec 22, 2021
Note: broken in 88f86a0
srittau commentedon Dec 22, 2021
Yeah, the return type of
__reduce__is documented, so we should revert this change. Cc @AlexWaygoodAlexWaygood commentedon Dec 22, 2021
Yes, my bad. Needs to be reverted, agreed.
Avoid mypy version 0.930
Fix 'object.__reduce__'
Fix 'object.__reduce__' (#6662)
Avoid mypy version 0.930
hauntsaninja commentedon Jan 7, 2022
@dvarrazzo this should be fixed in mypy 0.931, even if python/mypy#11820 isn't
dvarrazzo commentedon Jan 8, 2022
Yes, this is fixed alright :)