[ python-Bugs-945861 ] dir(object) does not list __name__
SourceForge.net
noreply at sourceforge.net
Tue May 11 22:55:22 EDT 2004
Bugs item #945861, was opened at 2004-05-01 07:39
Message generated for change (Comment added) made by fdrake
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=945861&group_id=5470
>Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Philips (tkpmep)
Assigned to: Nobody/Anonymous (nobody)
Summary: dir(object) does not list __name__
Initial Comment:
dir(object) returns
['__class__', '__delattr__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__new__', '__reduce__', '__reduce
_ex__', '__repr__', '__setattr__', '__str__']
The __name__ method is not reported
----------------------------------------------------------------------
>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2004-05-11 22:55
Message:
Logged In: YES
user_id=3066
I'm not convinced that attributes dynamically provided by
__getattr__() aren't actual attributes; it would be best if
dir() reported them if they're available via getattr(ob,
name). Whether or not this is practical is another matter.
I've just closed documentation bug #952212, so at least the
presence of the __name__ attribute on types and classes is
mentioned somewhere.
I'm re-classifying this bug report, since the dynamic
behavior of dir() is not a documentation issue.
----------------------------------------------------------------------
Comment By: Skip Montanaro (montanaro)
Date: 2004-05-02 15:47
Message:
Logged In: YES
user_id=44345
After a message from the submitter, it's apparent he was referring
to class objects not showing '__name__' attributes in dir() output.
This is a case of an attribute not being visible to dir() because it's
not directly present in the object's __dict__ and is trapped at
evaluation time by __getattr__(). Short of hacking dir() or adding
a special attribute ("__attributes__"?) to objects which have
__getattr__() methods I don't see a way around this problem.
Wasn't there discussion of such an attribute which would expose
such dynamic attributes to dir()? I don't see anything in the
implementation of PyObject_Dir().
----------------------------------------------------------------------
Comment By: Skip Montanaro (montanaro)
Date: 2004-05-01 21:02
Message:
Logged In: YES
user_id=44345
Are you sure that the object has an actual __name__ attribute
(and not something computed by a __getattr__ method)?
>>> import sys
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__',
'__stderr__', '__stdin__', '__stdout__', '_getframe', 'api_version',
'argv', 'builtin_module_names', 'byteorder', 'call_tracing',
'callstats', 'copyright', 'displayhook', 'exc_clear', 'exc_info',
'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit',
'exitfunc', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags',
'getfilesystemencoding', 'getrecursionlimit', 'getrefcount',
'hexversion', 'maxint', 'maxunicode', 'meta_path', 'modules', 'path',
'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2',
'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit',
'settrace', 'stderr', 'stdin', 'stdout', 'version', 'version_info',
'warnoptions']
>>> sys.__name__
'sys'
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=945861&group_id=5470
More information about the Python-bugs-list
mailing list