Skip to content

Instantly share code, notes, and snippets.

@pawelrubin
Last active December 10, 2020 11:57
Show Gist options
  • Save pawelrubin/a394702e4029809f30515621fc41ab1f to your computer and use it in GitHub Desktop.
Save pawelrubin/a394702e4029809f30515621fc41ab1f to your computer and use it in GitHub Desktop.
Protocol for annotating comparable types.
from __future__ import annotations
from abc import abstractmethod
from typing import TypeVar, Protocol
class Comparable(Protocol):
"""Protocol for annotating comparable types."""
@abstractmethod
def __lt__(self: CT, other: CT) -> bool:
pass
CT = TypeVar("CT", bound=Comparable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment