[issue22790] some class attributes missing from dir(Class)

2021-03-27 Thread Siddharth Chabra


Change by Siddharth Chabra :


--
nosy: +siddharthchabra
versions:  -Python 3.10, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2021-03-07 Thread Eryk Sun


Eryk Sun  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.

IMO, they're not interesting because they're not documented attributes in 
Python's data model. They don't exist in other implementations, such as PyPy. 
So I'd prefer to hide them and, as much as possible, discourage developers from 
thinking it's okay to use them. They may be interesting attributes while 
developing extension modules that define new types, but anyone working at that 
level surely doesn't need the help of dir() to know what attributes are 
available.

--
components: +Interpreter Core -Documentation
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.4, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2015-07-21 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
nosy:  -ethan.furman

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

Georg Brandl added the comment:

@Amaury: this is not what I read there:

If the object is a type or class object, the list contains the names of its 
attributes, and recursively of the attributes of its bases.

This implies that class attributes are definitely supposed to be in there.

--
nosy: +georg.brandl
resolution: works for me - 
status: pending - open
title: __qualname__ missing from dir(__class__) during class initialisation - 
some class attributes missing from dir(Class)

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Sam Bishop

Sam Bishop added the comment:

I specified 'during class initialisation' because that was the only case I 
confirmed.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

Georg Brandl added the comment:

The missing attributes are some of those defined in type_getsets, i.e.

__name__
__qualname__
__bases__
__abstractmethods__
__text_signature__

The latter two are obscure enough that it probably doesn't matter, but the 
first three should definitely be there.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

Georg Brandl added the comment:

Ah yes, and some type_members are also missing.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread eryksun

eryksun added the comment:

You won't find the __qualname__ data descriptor in dir(Foo.Bar) because it's 
defined by the metaclass, `type`. Attributes from the metaclass have always 
been excluded from the dir() of a class.

--
nosy: +eryksun

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread eryksun

eryksun added the comment:

See type_dir:

https://hg.python.org/cpython/file/ab2c023a9432/Objects/typeobject.c#l2984

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

Georg Brandl added the comment:

Attributes from the metaclass have always been excluded from the dir() of a 
class.

Be that as it may, I think it is wrong.  I can understand excluding methods of 
the metaclass, but __qualname__ (and friends) are only defined in the metaclass 
because they are properties and not __dict__ members, but they are regular 
attributes of the class, not of the metaclass.

E.g. why is __module__ in there and not __qualname__? Both are determined 
dynamically at class creation time.

The answer is that it's an implementation detail: there is no tp_module (or 
ht_module) member in the PyHeapTypeObject struct to store it, so it's stored in 
__dict__, while __qualname__ is stored in a struct member.

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

Georg Brandl added the comment:

BTW, the same implementation detail means that you can ask an instance for its 
class' __module__, but not the __name__.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

Georg Brandl added the comment:

However, it may not be possible to change this for backward compatibility 
reasons.  People shouldn't be using dir() for determining attributes and the 
like, but they do, as documented by the multiprocessing module in the stdlib.

This should at least be noted more explicitly in the docs for dir().

--
assignee:  - docs@python
components: +Documentation -Interpreter Core
nosy: +docs@python

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I definitely think this should be changed. I just don't know how to do it :-)

--
stage:  - needs patch
versions: +Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +benjamin.peterson

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

Georg Brandl added the comment:

Attaching prototype patch without test suite adjustments.

--
keywords: +patch
Added file: http://bugs.python.org/file37126/type_dir_patch.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I have a question: why would do it for classes and not for regular objects?

--
assignee: docs@python - 

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ah, I misunderstood the patch, sorry. Nevermind.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

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 rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

Changes by Georg Brandl ge...@python.org:


--
Removed message: http://bugs.python.org/msg230614

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread eryksun

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 rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Arfrever Frehtes Taifersar Arahesis

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 rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Amaury Forgeot d'Arc

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 rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

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 rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Ethan Furman

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 rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22790] some class attributes missing from dir(Class)

2014-11-04 Thread Georg Brandl

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 rep...@bugs.python.org
http://bugs.python.org/issue22790
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com