Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions data_structures/heap/heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

from abc import abstractmethod
from collections.abc import Iterable
from typing import Protocol, TypeVar
from typing import Protocol


class Comparable(Protocol):
@abstractmethod
def __gt__(self: T, other: T, /) -> bool:
def __gt__(self, other: object, /) -> bool:
pass


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


class Heap[T: Comparable]:
"""A Max Heap Implementation

Expand Down Expand Up @@ -253,7 +250,7 @@
]:
print(f"unsorted array: {unsorted}")

heap: Heap[int] = Heap()

Check failure on line 253 in data_structures/heap/heap.py

View workflow job for this annotation

GitHub Actions / ty

ty (invalid-type-arguments)

data_structures/heap/heap.py:253:20: invalid-type-arguments: Type `int` is not assignable to upper bound `Comparable` of type variable `T@Heap` data_structures/heap/heap.py:14:12: Type variable defined here info: type `int` is not assignable to protocol `Comparable` info: └── protocol member `__gt__` is incompatible info: └── parameter `other` has an incompatible type: `object` is not assignable to `int`
heap.build_max_heap(unsorted)
print(f"after build heap: {heap}")

Expand Down
Loading