[Python-ideas] Re: New attribute __convert__ for classes

2020-06-14 Thread Christopher Barker
On Sun, Jun 14, 2020 at 9:04 AM Oleg Broytman wrote: > On Sun, Jun 14, 2020 at 03:33:16PM -, artem6191 < > artem129...@gmail.com> wrote: > > This attribute will use for convertion classes to other types, i.e. > int(MyClass) will return __convert__ result in MyClass >Define ``__int__`` or

[Python-ideas] Re: New attribute __convert__ for classes

2020-06-14 Thread Jason Madden
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 ... d

[Python-ideas] Re: New attribute __convert__ for classes

2020-06-14 Thread Soni L.
On 2020-06-14 12:33 p.m., artem6191 wrote: This attribute will use for convertion classes to other types, i.e. int(MyClass) will return __convert__ result in MyClass Example: class MyClass: def __init__(self, numer: int): self.number = number def __convert__(self, type):

[Python-ideas] Re: New attribute __convert__ for classes

2020-06-14 Thread Oleg Broytman
On Sun, Jun 14, 2020 at 03:33:16PM -, artem6191 wrote: > This attribute will use for convertion classes to other types, i.e. > int(MyClass) will return __convert__ result in MyClass > > Example: > class MyClass: >def __init__(self, numer: int): > self.number = number >def __c