[Python-bugs-list] [ python-Bugs-826013 ] Class Problem with repr and getattr on PY2.3.2

SourceForge.net noreply at sourceforge.net
Mon Oct 20 07:33:56 EDT 2003


Bugs item #826013, was opened at 2003-10-18 16:36
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=826013&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Frank Timmermann (regenkind)
>Assigned to: Michael Hudson (mwh)
Summary: Class Problem with repr and getattr on PY2.3.2

Initial Comment:
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.

----------------------------------------------------------------------

>Comment By: Michael Hudson (mwh)
Date: 2003-10-20 12:33

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=826013&group_id=5470



More information about the Python-bugs-list mailing list