Skip to content

DisjointSet.__getitem__ has incorrect type #991

@lispandfound

Description

@lispandfound

The DisjointSet.__getitem__ method incorrectly sets the return type to int when it should probably be the generic _T.

The definition is here,

def __getitem__(self, x: _T, /) -> int: ...

Note that the current implementation of __getitem__ method indicates it is generic in its return type (and this is also my experience using this method).

    def __getitem__(self, x):
        """Find the root element of `x`.

        Parameters
        ----------
        x : hashable object
            Input element.

        Returns
        -------
        root : hashable object
            Root element of `x`.
        """
        if x not in self._indices:
            raise KeyError(x)

        # find by "path halving"
        parents = self._parents
        while self._indices[x] != self._indices[parents[x]]:
            parents[x] = parents[parents[x]]
            x = parents[x]
        return x

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions