zope.interface provides an implementation of PEP 246. That PEP defines a 
`__conform__` method objects can use to adapt themselves to a prototype:

>>> from zope.interface.common.numbers import IIntegral
>>> class MyClass:
...   def __init__(self, number: int):
...      self.number = number
...   def __conform__(self, prototype):
...       if prototype is IIntegral:
...          return self.number * 5
...
>>> IIntegral(MyClass(1))
5
_______________________________________________
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/4ONUXMAHPJMPH2RC2QYTFWXLOLHJ6VXO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to