Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue18693] help() not helpful with enum

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Aug 8, 2013, 6:59 PM

Post #1 of 12 (42 views)
Permalink
[issue18693] help() not helpful with enum

New submission from Ethan Furman:

help(), when used on an enum member or class, returns almost nothing. I suspect the custom __dir__ is at fault, but whatever is causing the problem needs fixing.

----------
assignee: ethan.furman
messages: 194714
nosy: barry, eli.bendersky, ethan.furman
priority: normal
severity: normal
status: open
title: help() not helpful with enum
versions: Python 3.4

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 8, 2013, 10:20 PM

Post #2 of 12 (41 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Ethan Furman added the comment:

With custom __dir__:

Help on class Enum in module enum:

Enum = <enum 'Enum'>

----------------------------------------------------

Without custom __dir__:

Help on class Enum in module enum:

class Enum(builtins.object)
| Generic enumeration.
|
| Derive from this class to define new enumerations.
|
| Methods defined here:
|
| __eq__(self, other)
|
| __getnewargs__(self)
|
| __hash__(self)
|
| __repr__(self)
|
| __str__(self)
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(cls, value)
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| name
| Route attribute access on a class to __getattr__.
|
| This is a descriptor, used to define attributes that act differently when
| accessed through an instance and through a class. Instance access remains
| normal, but access to an attribute through a class will be routed to the
| class's __getattr__ method; this is done by raising AttributeError.
|
| value
| Route attribute access on a class to __getattr__.
|
| This is a descriptor, used to define attributes that act differently when
| accessed through an instance and through a class. Instance access remains
| normal, but access to an attribute through a class will be routed to the
| class's __getattr__ method; this is done by raising AttributeError.

---------------------------------------------------------------

I'm thinking we should drop the custom __dir__. help() is far more important than not seeing some things with dir().

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2013, 1:07 PM

Post #3 of 12 (29 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Roundup Robot added the comment:

New changeset 5d417257748e by Ethan Furman in branch 'default':
Close #18693: __dir__ removed from Enum; help() now helpful.
http://hg.python.org/cpython/rev/5d417257748e

----------
nosy: +python-dev
resolution: -> fixed
stage: -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2013, 2:08 PM

Post #4 of 12 (29 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Eli Bendersky added the comment:

Less than two days passed since this issue was opened. No waiting for feedback? No patch? No code review?

Maybe there's another solution? Personally I find dir() often more useful than help(). Maybe help() can be adapted to behave nicely for classes with custom __dir__ and it could be useful elsewhere?

Is this such a burning immediate need that we forego all the usual discussion channels?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2013, 10:57 PM

Post #5 of 12 (28 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Ethan Furman added the comment:

Sorry, sorry.

Long week, felt like more than two days, mild sense of unease and stress due to non-functioning Release Schedule on python.org, and wanting to get Enum used /somewhere/ in the stdlib before 3.4 is locked down.

Making help() better would be a better solution, especially if we enhanced it to show docstrings on instances.

I'll see what I can figure out. Feel free to beat me to it. :)

----------
status: closed -> open

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2013, 1:28 AM

Post #6 of 12 (26 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Ned Deily added the comment:

Ethan, http://www.python.org/dev/peps/pep-0429/#release-schedule
TL;DR - no new features after beta 1 (2013-11-24), no non-release-critical bug fixes after rc1 (2014-01-19)

----------
nosy: +ned.deily

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2013, 5:42 AM

Post #7 of 12 (25 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Eli Bendersky added the comment:

Ethan, as Ned said (and I think you got this answer in the list before), the real feature cutoff is Beta 1. So we have time until the end of November. Note that even new PEPs (like the statistics one) can go in before that. Even after beta, things that appear to be bugs (like this issue) can usually be fixed before the RCs come. So there is no time pressure whatsoever.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2013, 5:05 PM

Post #8 of 12 (22 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Ethan Furman added the comment:

So what do we want Enum's __dir__ to report?

Normally we see things like __eq__, __dict__, __getnewargs__, etc.

For IntEnum there would be __abs__, __floor__, __div__, etc.

Do we want to worry about those kinds of differences? I think we do.

And if we do, then we are looking at removing items to make our custom __dir__, and with each release we would have to revisit the blacklist of items we don't want (the tests would catch that for us, but it would still be effort to update the code).

What if we took what object.__dir__ gave us, then added the Enum members while removing the private, er, non-public data structures?

In other words, this dir in EnumMeta:

def __dir__(cls):
items = set(super().__dir__())
disgard = set([m for m in items if _is_sunder(m)])
members = set(cls.__members__)
return sorted((items | members) ^ disgard)

with this Enum:

>>> class Color(enum.Enum):
... RED = 1
... BLUE = 2
... GREEN = 3
...

gives us this result:

>>> dir(Color)
[.'BLUE', 'GREEN', 'RED', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'name', 'value']

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 11, 2013, 11:11 PM

Post #9 of 12 (22 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Ethan Furman added the comment:

Huh. I just checked `help(Color)` on my proposed __dir__ and got the two-line, rather useless, response. Perhaps help() is broken with all custom __dir__s.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 5:47 AM

Post #10 of 12 (17 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Eli Bendersky added the comment:

Ethan, please revert your commit first. I liked the previous dir. The current one is useless.

I think you may be right about help, but I didn't dig deep enough to be sure.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 5:51 AM

Post #11 of 12 (17 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Changes by Ronald Oussoren <ronaldoussoren [at] mac>:


----------
nosy: +ronaldoussoren

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 12, 2013, 6:51 AM

Post #12 of 12 (11 views)
Permalink
[issue18693] help() not helpful with enum [In reply to]

Roundup Robot added the comment:

New changeset 39697dcd97e3 by Ethan Furman in branch 'default':
Issue 18693: Put custom __dir__ back in place. Will instead look at fixing `help()`.
http://hg.python.org/cpython/rev/39697dcd97e3

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue18693>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.