[Python-Dev] str does not default to repr if a base class has str (original) (raw)
Edward C. Jones edcjones at erols.com
Mon May 17 10:57:57 EDT 2004
- Previous message: [Python-Dev] Relative vs. absolute imports
- Next message: [Python-Dev] __str__ does not default to __repr__ if a base class has __str__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In the code below, "a.str()" does not default to "a.repr() as
might be expected. It finds the "str" in the base class X. The
Reference Manual, section 3.3.1, says:
If a class defines repr() but not str(), then repr() is
also used when an 'informal' string representation of instances of
that class is required.
If the reader is in lawyer mode, the documentation is correct.
Is the current behavior what was intended? What should the behavior be?
class X(object): def str(self): return 'str for X'
def __repr__(self):
return 'repr for X'
class A(X): def repr(self): return 'repr for A'
str = repr
x = X() a = A() print x.str() print x.repr() print a.str() print a.repr()
- Previous message: [Python-Dev] Relative vs. absolute imports
- Next message: [Python-Dev] __str__ does not default to __repr__ if a base class has __str__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]