[Python-ideas] Fix that broken callable builtin
Ionel Cristian Mărieș
contact at ionelmc.ro
Sat Apr 18 00:14:18 CEST 2015
Same as what would happen when you use the call operator on an object that
has an AttributeError raising property:
>>> class D:
> ... @property
> ... def __add__(self):
> ... raise AttributeError('Not so fast, pardner!')
> ...
> >>> D() + D()
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 4, in __add__
> AttributeError: Not so fast, pardner!
Thanks,
-- Ionel Cristian Mărieș, http://blog.ionelmc.ro
On Sat, Apr 18, 2015 at 12:44 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 04/18, Ionel Cristian Mărieș wrote:
>
> > __add__ as a property/descriptor seems to work fine, eg:
> >
> > >>> class C:
> > > ... @property
> > > ... def __add__(self):
> > > ... return lambda other: [self, other]
> > > ...
> > > >>> C() + C()
> > > [<__main__.C object at 0x0000000003652AC8>, <__main__.C object at
> > > 0x0000000003652CC0>]
> > >
> >
> > Am I missing something?
>
> What happens when your __add__ raises an AttributeError?
>
> --
> ~Ethan~
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150418/895c155f/attachment-0001.html>
More information about the Python-ideas
mailing list