
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2022-04-07 22:21 byapostofes, last changed2022-04-11 14:59 byadmin.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 32408 | closed | apostofes,2022-04-07 22:47 | |
| Messages (4) | |||
|---|---|---|---|
| msg416948 -(view) | Author: apostofes (apostofes)* | Date: 2022-04-07 22:21 | |
current dir gives output like this,```from collection import OrderedDictod = OrderedDict({'a': 1, 'b': 2, 'c': 3})print(dir(od))``````['__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'move_to_end', 'pop', 'popitem', 'setdefault', 'update', 'values']```but wouldn't it be better if the output was like this,```{'OrderedDict': {'__contains__', '__delitem__', '__dir__', '__eq__', '__format__', '__ge__', '__getitem__', '__gt__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__ne__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setitem__', '__sizeof__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'move_to_end', 'pop', 'popitem', 'setdefault', 'update', 'values'},'dict': {'__getattribute__', '__len__', '__new__'},'object': {'__delattr__', '__setattr__', '__str__'}}```??? | |||
| msg416951 -(view) | Author: Jelle Zijlstra (JelleZijlstra)*![]() | Date: 2022-04-07 23:55 | |
This would be nice, but backward compatibility alone means we can't change dir() to return a dictionary. What you propose would make more sense as a new function, perhaps in a package like pydoc or a third-party tool like IPython. | |||
| msg416954 -(view) | Author: apostofes (apostofes)* | Date: 2022-04-08 00:30 | |
would adding an argument to dir be a possible solution,like,```l = [1, 2, 3]dir(l, categorize=True)``` | |||
| msg416955 -(view) | Author: apostofes (apostofes)* | Date: 2022-04-08 01:33 | |
plus I would want it to have some more methods,```l = [1, 2, 3]```using enhanced dir should give,```{'list': {'__add__', '__contains__', '__delitem__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__repr__', '__reversed__', '__rmul__', '__setitem__', '__sizeof__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'},'object': {'__delattr__', '__dir__', '__format__', '__reduce__', '__reduce_ex__', '__setattr__', '__str__'}}```obtained from, (here only printing, made a dictionary in the implementation in the PR)```for j in dir(l): print(f'l.{j}.__qualname__')```this check fails for,```{'list': {'__doc__', '__hash__', '__class__'}}```I would also want these,```{'list': {'__instancecheck__','__subclasscheck__', '__subclasses__', 'mro'}, 'type': {'__call__', '__prepare__'}}```which were obtained from,```for j in set(dir(type(l))) - set(dir(l)): print(f'l.{j}.__qualname__')```and it fails for,```{'list': {'__abstractmethods__', '__base__', '__bases__', '__basicsize__', '__dict__', '__dictoffset__', '__flags__', '__itemsize__', '__module__', '__mro__', '__name__', '__qualname__', '__text_signature__', '__weakrefoffset__'}``` | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:58 | admin | set | github: 91410 |
| 2022-04-08 01:33:59 | apostofes | set | messages: +msg416955 |
| 2022-04-08 00:30:53 | apostofes | set | messages: +msg416954 |
| 2022-04-07 23:55:13 | JelleZijlstra | set | nosy: +JelleZijlstra messages: +msg416951 |
| 2022-04-07 22:47:11 | apostofes | set | keywords: +patch stage: patch review pull_requests: +pull_request30433 |
| 2022-04-07 22:21:22 | apostofes | create | |