Skip to content

Regression in mypy 0.930: object.__reduce__ #6661

Closed

Description

@dvarrazzo

In mypy 0.930 the signature for object.__reduce__ has been changed to

    def __reduce__(self) -> str | Tuple[object, ...]: ...

This is wrong, reading the documentation. The following valid code now is reported as error:

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

  1. dvarrazzo commented on Dec 22, 2021

    @dvarrazzo
    Author

    Note: broken in 88f86a0

  2. srittau commented on Dec 22, 2021

    @srittau
    Collaborator

    Yeah, the return type of __reduce__ is documented, so we should revert this change. Cc @AlexWaygood

  3. AlexWaygood commented on Dec 22, 2021

    @AlexWaygood
    Member

    Yes, my bad. Needs to be reverted, agreed.

  4. added a commit that references this issue on Dec 22, 2021
  5. added a commit that references this issue on Dec 22, 2021
    0bd5883
  6. added a commit that references this issue on Dec 22, 2021
    1ec2387
  7. added a commit that references this issue on Dec 23, 2021
  8. hauntsaninja commented on Jan 7, 2022

    @hauntsaninja
    Collaborator

    @dvarrazzo this should be fixed in mypy 0.931, even if python/mypy#11820 isn't

  9. dvarrazzo commented on Jan 8, 2022

    @dvarrazzo
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions