-
-
Notifications
You must be signed in to change notification settings - Fork 25
Labels
Milestone
Description
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