Skip to content

Regression in 0.930 - Slots  #11821

Closed
@TylerYep

Description

@TylerYep

Bug Report

This error is incorrectly showing up on my class that inherits from Generic[V]. This is probably because it inherits from Protocol, which defines __slots__ = ()
error: "Node" both defines "slots" and is used with "slots=True" [misc]

To Reproduce


C = TypeVar("C", bound="Comparable")

class Comparable(Protocol):
    @abstractmethod
    def __eq__(self, other: Any) -> bool:
        pass

    @abstractmethod
    def __lt__(self: C, other: C) -> bool:
        pass

    def __gt__(self: C, other: C) -> bool:
        return (not self < other) and self != other

    def __le__(self: C, other: C) -> bool:
        return self < other or self == other

    def __ge__(self: C, other: C) -> bool:
        return not self < other


V = TypeVar("V", bound=Comparable)

@dataclass(slots=True)
class Node(Generic[V]):
    data: V

Expected Behavior

This should not cause an error.

Actual Behavior
error: "Node" both defines "slots" and is used with "slots=True" [misc]

Your Environment

  • Mypy version used: 0.930
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.10
  • Operating system and version: Mac OS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions