On Sun, Jun 14, 2020 at 9:04 AM Oleg Broytman <p...@phdru.name> wrote:

> On Sun, Jun 14, 2020 at 03:33:16PM -0000, 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 ``__index__``.
>

or __float__

But the problem is that we need a dunder for each type you want to support.
I think the idea here is that you could specify, in your own custom class,
which type(s) you can convert to, and it could be any type.

That being said, to the OP:

what are your use cases here? adding a dunder requires compelling use
cases, and in this case, why having a dunder would be more helpful that
simply writing a convert to this type method on your class.

And when would that dunder be called? I'm having trouble figuring that out.

-CHB




>    See
> https://docs.python.org/3/reference/datamodel.html#special-method-names
>
> Oleg.
> --
>     Oleg Broytman            https://phdru.name/            p...@phdru.name
>            Programmers don't die, they just GOSUB without RETURN.
> _______________________________________________
> 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/PTAVFYSXD4KTUYJCBWO7GB7F5QOH6Z5N/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
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/FNXMKLLJ665DMQCRQCQ6DZERNGQGC43N/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to