[Python-bugs-list] [ python-Bugs-445096 ] hasattr does not support name mangling
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 27 Jul 2001 02:18:19 -0700
Bugs item #445096, was opened at 2001-07-27 02:18
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=445096&group_id=5470
Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: asbjorn christensen (asbjorntheman)
Assigned to: Nobody/Anonymous (nobody)
Summary: hasattr does not support name mangling
Initial Comment:
-----------------------------------------------
Description =
Apparently hasattr() is not aware of the
name mangling performed on instance attributes
with names "__somename", so that
hasattr(self, "__somename") generally gives false
I have provided an example below.
It is easy to circumvent (e.g. with a
try clause), but most programmers will find this
behavior of hasattr() unexpected. It would be
nice to have it ironed out. I'm not deeply enough
into the parser to provide a fix myself, sorry.
Unfortunately, I don't have access to platforms
running Python version > 1.5.2
I was not able to find this problem mentioned
in the bug reports
Best wishes, Asbjorn
-----------------------------------------------
Version details =
Python 1.5.2 (#1, Mar 3 2001, 01:35:43) [GCC 2.96
20000731 (Red Hat Linux 7.1 2 on linux-i386
-----------------------------------------------
Example =
class a:
def __init__(self, x):
self.__dat = x
def test(self):
print "hasattr(self, '__dat') =",
hasattr(self, '__dat')
print "hasattr(self, '_a__dat') =",
hasattr(self, '_a__dat')
print "self.__dat= =", self.__dat
an_a = a(77)
an_a.test()
---------------------------------------------------
Std output =
hasattr(self, '__dat') = 0
hasattr(self, '_a__dat') = 1
self.__dat= = 77
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=445096&group_id=5470