[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2022-01-13 Thread Ethan Furman


Ethan Furman  added the comment:

Ram asked:
-
> Also, aren't you excluding a lot of important magic methods from that `dir`?

Ethan replied:
-
> We decided the dunder methods were not interesting, so declined to include
> them in the listing.  And no, we are not changing our minds on that.  ;)

--

UPDATE:  We have changed our minds, but only for enums that have a data type, 
such as `int` or `str`, mixed in.  This behavior should be in 3.11.

--

___
Python tracker 

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-21 Thread Ram Rachum

Ram Rachum added the comment:

Thanks for the fix Ethan. Will you also push this to the backport on PyPI?

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-21 Thread Ethan Furman

Ethan Furman added the comment:

Thanks for the reminder!

...

Done.

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-21 Thread Ram Rachum

Ram Rachum added the comment:

Thanks!

Two questions:

1. Is there a GitHub repo for enum34? Couldn't find a link to it on the PyPI 
page.

2. Aren't 'name' and 'value' already included in `added_behavior`?

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-21 Thread Ram Rachum

Ram Rachum added the comment:

Also, aren't you excluding a lot of important magic methods from that `dir`?

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-21 Thread Ethan Furman

Ethan Furman added the comment:

 1. Is there a GitHub repo for enum34? Couldn't find a link to it on the PyPI 
 page.

The repo is at:  https://bitbucket.org/stoneleaf/enum34


 2. Aren't 'name' and 'value' already included in `added_behavior`?

They didn't used to be, but they are now.  I'll fix that (eventually).


 Also, aren't you excluding a lot of important magic methods from that `dir`?

We decided the dunder methods were not interesting, so declined to include them 
in the listing.  And no, we are not changing our minds on that.  ;)

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-21 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 9038b63dad52 by Ethan Furman in branch 'default':
Issue22506: remove name  value from __dir__ as they now show up automatically
https://hg.python.org/cpython/rev/9038b63dad52

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-14 Thread Roundup Robot

Roundup Robot added the comment:

New changeset cd2ede7f2ff5 by Ethan Furman in branch '3.4':
Issue22506: added methods on base Enum class now show up in dir of Enum 
subclass (3.4)
https://hg.python.org/cpython/rev/cd2ede7f2ff5

New changeset 424fbf011176 by Ethan Furman in branch 'default':
Issue22506: merge from 3.4
https://hg.python.org/cpython/rev/424fbf011176

--
nosy: +python-dev

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-14 Thread Ethan Furman

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


--
assignee:  - ethan.furman
resolution:  - fixed
stage: test needed - resolved
status: open - closed
versions: +Python 3.5

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-10 Thread Ethan Furman

Ethan Furman added the comment:

Sample code:

class AutoEnum(enum.Enum):

Automatically numbers enum members starting from 1.

Includes support for a custom docstring per member.

__last_number__ = 0
def __new__(cls, *args):

Ignores arguments (will be handled in __init__.

value = cls.__last_number__ + 1
cls.__last_number__ = value
obj = object.__new__(cls)
obj._value_ = value
return obj
def __init__(self, *args):

Can handle 0 or 1 argument; more requires a custom __init__.
0  = auto-number w/o docstring
1  = auto-number w/ docstring
2+ = needs custom __init__

if len(args) == 1 and isinstance(args[0], str):
self.__doc__ = args[0]
elif args:
raise TypeError('%s not dealt with -- need custom __init__' % 
(args,))

class AddressSegment(AutoEnum):
misc = not currently tracked
ordinal = N S E W NE NW SE SW
secondary = apt bldg floor etc
street = st ave blvd etc

def huh(self):
return 'did I show up?'


The 'huh' function, shown above, does *not* show up in a dir of either AutoEnum 
nor AddressSegment, regardless of which class it is defined in -- this is 
because a directory of an Enum class is meant to show ['__class__', '__doc__', 
'__members__', '__module__'] + whatever Enum members have been defined.

However, a directory of an Enum member should show any normal methods* 
available on that member.  Currently, if 'huh' is defined in the final class it 
will show up, but if defined in a superclass it will not.

That is the bug.


* 'normal method' means any method not prefixed by any underscores.

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-10 Thread Ram Rachum

Ram Rachum added the comment:

Ethan: I'm very confused by your example. `huh` isn't even a method, why would 
it be included? Or are you saying if it was a method? I'm really not sure 
what your example is adding over mine, given that it's 10 times longer and more 
complex. I'm not sure why you'd want to demonstrate the bug in a 50-line code 
sample that has non-trivial logic when it's demonstrable in a simple 5-line 
code sample.

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-10-10 Thread Ethan Furman

Ethan Furman added the comment:

Yes, the 'huh' function would have to be in either AutoEnum or AddressSegment 
to be included in the dir of an AddressSegment member.

Here's a shorter example:

(this works)

class SuperEnum(Enum):
pass

class SubEnum(SuperEnum):
sample = 5
def visible(self):
return saw me, right?

'visible' in dir(SubEnum.sample)


(this does not work)

class SuperEnum(Enum):
def invisible(self):
return but you didn't see me!

class SubEnum(SuperEnum):
sample = 5

'invisible' in dir(SubEnum.sample)


Sorry for the noise.

Do please note that the dir where 'visible' showed up was on the Enum member, 
not the Enum class.

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-09-27 Thread Ram Rachum

New submission from Ram Rachum:

Calling `dir` on an enum subclass shows only the contents of that class, not 
its parent classes. In normal classes, you can do this: 

Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 
bit (AMD64)] on win32
Type help, copyright, credits or license for more information.
 class A:
...   x = lambda self: 7
...
 class B(a): pass
...
 assert 'x' in dir(B)

But in enum subclasses, it fails:

 import enum
 class A(enum.Enum):
...   x = lambda self: 7
...
 class B(A):
...   pass
...
 assert 'x' in dir(B)
Traceback (most recent call last):
  File stdin, line 1, in module
AssertionError


Looks like the `__dir__` implementation needs to be tweaked.

--
components: Library (Lib)
messages: 227681
nosy: cool-RR
priority: normal
severity: normal
status: open
title: `dir` on Enum subclass doesn't expose parent class attributes
type: behavior
versions: Python 3.4

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-09-27 Thread Ethan Furman

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


--
nosy: +ethan.furman

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-09-27 Thread Ethan Furman

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


--
stage:  - test needed

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-09-27 Thread Ram Rachum

Ram Rachum added the comment:

Ethan, I saw you just marked this as test needed. I just gave you code to 
reproduce this problem. Isn't that sufficient? Or you want me to do add it to 
Python's test suite?

--

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



[issue22506] `dir` on Enum subclass doesn't expose parent class attributes

2014-09-27 Thread Ethan Furman

Ethan Furman added the comment:

More just a note to myself to research this further, to see exactly what does 
and does not get inherited.  Any tests added will likely be more comprehensive 
than your example.

--

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