A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-July/007616.html below:

[Python-Dev] buglet in unary ops on classes.

[Python-Dev] buglet in unary ops on classes.Thomas Wouters thomas@xs4all.net
Fri, 28 Jul 2000 18:45:12 +0200
While poking around looking for something else, I found this little buglet:

>>> class X:
...     def __getattr__(self, val):
...             print "getattr:", val
...             raise AttributeError

>>> x = X()
>>> ~x
getattr: __invert__
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 4, in __getattr__
AttributeError

The unary ops all do this (raising AttributeError), but the binary ops do
not:

>>> x+1
getattr: __coerce__
getattr: __add__
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: __add__ nor __radd__ defined for these operands

Shouldn't this translation be done for unary ops as well ? Is it safe to
assume that instance_getattr() only returns NULL if the attribute is not
found ? PyInstance_DoBinOp() takes this assumption wrt. PyObject_GetAttr(),
and I don't really see a problem with it.

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4