Currently there are a few Protocols https://docs.python.org/3/library/typing.html#protocols defined in the typing module. One that I recently felt like was missing was a typing annotation for classes with a __str__() method defined. Seems like a fairly straightforward implementation.
@runtime_checkable |
class SupportsString(Protocol):
"""An ABC with one abstract method __str__.""" |
__slots__ = () |
|
@abstractmethod |
def __str__(self) -> str: |
pass |
Perhaps there is another way to do this that I am missing?