[Python-ideas] Allow __bytes__ to return NotImplemented
Serhiy Storchaka
storchaka at gmail.com
Tue Jun 7 00:51:26 EDT 2016
On 06.06.16 20:05, Émanuel Barry wrote:
> While I'm at it, maybe other methods could use that, too (thinking mainly of
> __int__, __float__, __abs__, __complex__, __round__, __index__, and maybe
> __len__ and __iter__).
This would break a lot of code that just checks the existence of
corresponding methods. Even if change all this code to call
corresponding methods and check the result, this would affect the
performance.
> Thoughts? Is it reasonable to define a single class that can work with both
> str and bytes, or should I fix my code?
Define tree classes. A base class, its constructor returns an instance
of appropriate child class, and two child classes for str and bytes.
More information about the Python-ideas
mailing list