[Python-ideas] Should we improve `dir`?
Mark Janssen
dreamingforward at gmail.com
Sun Sep 15 03:37:05 CEST 2013
> I recently stumbled over `dir()` not working correctly in the case of
> classes:
Not working correctly? That would imply an adequate definition of
"correctness".
Dir should divulge all method and attribute names of a class -- a
"directory", as it were. In my opinion, it should not report
__bases__, __name__, __doc__, or __class__ -- all of which are
meta-things not meant for the user of a class. If a programmer wants
to see more, then the inspect module would presumably be appropriate,
or simply calling for help().
--mark
>
> http://jedidjah.ch/code/2013/9/8/wrong_dir_function/
>
> In short:
>
> `dir` doesn't list the `type` methods, which it should in my opinion,
> because there are very important attributes in there like `__name__` or
> `__bases__`.
>
> This led to some confusion in the past, e.g.
> http://www.gossamer-threads.com/lists/python/python/507363.
>
> The long version is in the above link.
>
> After discussions, I realized that I should probably bring this up in
> python-ideas, I think the current implementation can be very confusing for
> people trying to introspect classes with `dir`, which is IMHO its typical
> use case.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
>
--
MarkJ
Tacoma, Washington
More information about the Python-ideas
mailing list