Finding the name of a class

S

Shane Hathaway

John said:
I'm reluctant to call it a bug just yet. Here's more stuff below.
There's obviously a difference between old- and new-style classes. It
seems that as far as new-style is concerned, __name__ is an attribute of
__class__ (along with a bunch of other stuff), but not of Foo itself.

I'm not sure what you're saying. The class of a class is the 'type'
builtin, unless metaclasses are involved. So your expression
"dir(Foo.__class__)" is equivalent to "dir(type)", and the 'type'
builtin happens to have a __name__ attribute that dir() notices. Take a
look:
.... pass
....'type'

The bug is that the expression "dir(someclass)", where the class is a
user-defined class of either new or old style, never reveals to the user
that the class object has a __name__ attribute. I tested this with
Python versions 2.3 through 2.5b1. This is an education issue; since
that important attribute is not in the list, newcomers are not likely to
discover it, and may instead use strange incantations to get the name of
a class.

Do you want me to file the bug?

Shane
 
J

John Salerno

Shane said:
The bug is that the expression "dir(someclass)", where the class is a
user-defined class of either new or old style, never reveals to the user
that the class object has a __name__ attribute.

I guess maybe it is a bug. This seems to be the relevant code to prove it:
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__']'Foo'


Tim can report it if he wants, since he found it first. Otherwise I'll
do it and it will give me a chance to see how the bug reporting process
works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top