Raymond Hettinger added the comment:
Georg's proposed wording reads well and is clearer than the current wording. The patch is ready to apply.
----------
nosy: +rhettinger
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22525>
_______________________________________
Georg Brandl added the comment:
> Why are __flags__, __basicsize__, __itemsize__, __dictoffset__, and __weakrefoffset__ interesting?
I haven't said they are, but on the other hand I don't see why consistency is a bad thing.
----------
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22790>
_______________________________________
Ethan Furman added the comment:
Why are __flags__, __basicsize__, __itemsize__, __dictoffset__, and __weakrefoffset__ interesting?
I agree with Georg about the others.
----------
nosy: +ethan.furman
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22790>
_______________________________________
Georg Brandl added the comment:
> So, dir(C) contains '__mro__', but not 'mro'?
That can be discussed.
But I would argue that at least __name__, __bases__ and __qualname__ are interesting attributes for the user. Same for methods like __subclasses__().
Otherwise, it's quite ironic to prevent attributes that allow introspection in the first place from being displayed in one of the main features used for introspection.
----------
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22790>
_______________________________________
Amaury Forgeot d'Arc added the comment:
So, dir(C) contains '__mro__', but not 'mro'?
I'm -1 on the change.
>From https://docs.python.org/3.4/library/functions.html#dir :
"""
Note Because dir() is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases. For example, metaclass attributes are not in the result list when the argument is a class.
"""
dir(sys) does not list its __str__ method, even if sys.__str__() works, because returning only the explicit content of the module is more interesting to the user.
Likewise, the implementation of dir(__class__) returns the methods and attributes of *instances* because [someone decided that] it's the most relevant info for the user.
----------
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22790>
_______________________________________
Arfrever Frehtes Taifersar Arahesis added the comment:
__base__ exists also in Jython and PyPy (#22456).
I think that all attributes could be listed.
----------
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22790>
_______________________________________
R. David Murray added the comment:
To clarify for the OP: in python3 the 'string' module does not contain a replace function, whereas in 2.7 it did. 'replace' is only a method on str in python3, whereas in 2.7 it is both an str method and a function in the string module.
----------
nosy: +r.david.murray
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22792>
_______________________________________
eryksun added the comment:
__doc__ and __module__ are also getsets (to support built-in types), but it's nothing to worry about since the attributes can't be deleted.
I think the most value added here is for listing __mro__ and the others that Georg mentioned. Should the following attributes be blacklisted from dir() as CPython implementation details?
__base__
__flags__
__basicsize__
__itemsize__
__dictoffset__
__weakrefoffset__
It's not as if people will miss what they never had.
----------
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22790>
_______________________________________
Georg Brandl added the comment:
Basically beacuse with the current patch, this is because object_dir also does merge_class_dict, to get class attributes. This means that attributes like __qualname__ would show up in dir(instance), but are not actually available on the instance.
Fixing this requires a more substantial rewrite, but is certainly the right way if this is accepted at all.
----------
_______________________________________
Python tracker <report(a)bugs.python.org>
<http://bugs.python.org/issue22790>
_______________________________________