This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Class Problem with repr and getattr on PY2.3.2
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: mwh Nosy List: mwh, regenkind
Priority: normal Keywords:

Created on 2003-10-18 15:36 by regenkind, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg18689 - (view) Author: SomeOne (regenkind) Date: 2003-10-18 15:36
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 
32 bit (Intel)] on win32
IDLE 1.0
>>> class A:
	def __init__(self): self.x=1
	def __repr__(self): return "REPR"
	def __getattr__(self,name): return "GETATTR"

	
>>> a=A()
>>> a
REPR
>>> print a

Traceback (most recent call last):
  File "<pyshell#24>", line 1, in -toplevel-
    print a
TypeError: 'str' object is not callable
>>> if a: print 1

Traceback (most recent call last):
  File "<pyshell#26>", line 1, in -toplevel-
    if a: print 1
TypeError: 'str' object is not callable
>>> 

Everything works fine without the __getattr__ code.
msg18690 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2003-10-20 11:33
Logged In: YES 
user_id=6656

you're returning a string in response to a request for
__str__ and (I'd guess) __nonzero__.

Don't do that, raise AttributeError instead.
History
Date User Action Args
2022-04-11 14:56:00adminsetgithub: 39429
2003-10-18 15:36:29regenkindcreate