The nice thing about Protocols is that they are so easy to define, you can
just define them yourself. There's no need to have a "standard" protocol in
typing.py for ever single dunder method in existence.

PS. There's no need for `__slots__ = ()` assuming you're not going to
inherit directly from it (there's really no point).

On Tue, Oct 6, 2020 at 10:29 AM aleksiy123 <aleksiy...@gmail.com> wrote:

> 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?
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/C66MLTYQNAL3KHZELGME62UQOVGAHM5L/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UOL3NKKVTQCWPYICL6XITMPX44RMAYMC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to