Ethan Furman added the comment:
Terry remarked:
---
> I am puzzled by the opening statement there that
>
> from enum import Enum # I added this as necessary
> class Season(Enum):
> SPRING = Season()
>
> "works beautifully" at top level as it
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue2506>
___
___
Python-bugs-list mailing list
Unsubscribe:
Ethan Furman added the comment:
Good work.
This bug was fixed in 3.4 with the inclusion of enum.
It would definitely be good to fix in 2.7 as well.
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue21
Ethan Furman added the comment:
The problem will affect anything that uses the same mechanism as enum. It also
affects (not verified) all versions of python up to 3.4 where it was fixed
because enum exposed it.
Besides which, I did not think a bug had to affect stdlib code in order to be
Ethan Furman added the comment:
I think something like the following, taken from
http://bugs.python.org/issue19030#msg199920, shoud do the trick for something
to test against:
class Meta(type):
def __getattr__(self, name):
if name == 'ham':
re
Ethan Furman added the comment:
That is certainly nicer than the current idiom:
Animal = Enum('Animal', zip('ant bee cat dog'.split(), range(4)))
--
assignee: -> ethan.furman
___
Python tracker
<http://
Ethan Furman added the comment:
Playing devil's advocate:
The issue is not so much the keystrokes saved as the improvement in reading and
understanding what was intended. If you are happy with starting at 1 the idiom
is easy to both write, read, and understand; but if you want some
New submission from Ethan Furman:
Replacing __new__ in an Enum subclass is not possible /in the subclass
definition/, but is easily replaced via monkey-patching after the class has
been defined.
Docs need to be updated to reflect this.
--
assignee: ethan.furman
messages: 220372
nosy
Ethan Furman added the comment:
Right, I had copied that code from test_pydoc which is where 'print_diffs' is
defined.
A comment there says to use the now-included functionality in unittest, and
some digging in the docs revealed that assertEqual uses diffs by default.
-
Ethan Furman added the comment:
Left comments in reitvald about modifying the Enum used -- let me know if you
have any questions about that.
--
___
Python tracker
<http://bugs.python.org/issue21
Ethan Furman added the comment:
Common, no. And if the docs were silent on the matter that would be okay, but
unfortunately the docs declare that it is not possible, which is just plain
wrong.
Patch also mentions _value_ as that is the supported interface when customizing
__new__ methods
Ethan Furman added the comment:
There is one typo and one error in the first paragraph of the patch:
> When raising a new exception (rather than
> using to bare ``raise`` to re-raise the
^ should be an 'a'
> exception currently being handled), the
> implicit
Ethan Furman added the comment:
True, but how big a deal is that?
For one, it seems questionable to have the presentation portion of the data be
part of the key.
For two, when presentation is important a separate list must be kept anyway to
preseed the dict; so just use that list to cycle
Ethan Furman added the comment:
Right, sorry.
--
___
Python tracker
<http://bugs.python.org/issue18986>
___
___
Python-bugs-list mailing list
Unsubscribe:
Ethan Furman added the comment:
One cannot subclass an Enum that has already defined keys.
--
___
Python tracker
<http://bugs.python.org/issue18989>
___
___
Pytho
Ethan Furman added the comment:
Perhaps you meant, what if you define a key in a subclass that shadows a
method/property in a parent class?
I'm inclined to say that would be acceptable, since one reason for subclassing
is to add or make changes to the parent class'
Ethan Furman added the comment:
In any other (normal) class, this works:
==
-->class Okay:
... red = 1
... green = 2
... blue = 3
... red
Ethan Furman added the comment:
--> class Test:
... this = 'that'
... these = 'those'
...
--> Test.this
'that'
--> Test.this.these
Traceback (most recent call last):
Fi
Ethan Furman added the comment:
My apologies, you are correct.
I am still against this for the Alice reason, but lets see what the others
think.
--
resolution: rejected ->
status: closed -> open
___
Python tracker
<http://bugs.p
Ethan Furman added the comment:
That is expressly forbidden in the PEP. Can we change it now?
--
___
Python tracker
<http://bugs.python.org/issue18989>
___
___
Ethan Furman added the comment:
Well, I totally messed up the commit message, but the code is now in place.
Thanks, Vajrasky Kok!
--
resolution: -> fixed
stage: patch review -> committed/rejected
status: open -> closed
___
Python track
Ethan Furman added the comment:
Okay, here's the patch after the inspect portion was committed in #18929.
Summary:
- added __objclass__ to each enum member
- added __module__ to the class dir
- aded any extra methods defined to the instance dir
- changed _RouteClassAttributeToGetat
Changes by Ethan Furman :
--
assignee: -> ethan.furman
___
Python tracker
<http://bugs.python.org/issue19025>
___
___
Python-bugs-list mailing list
Unsubscrib
Ethan Furman added the comment:
Perhaps a section in the docs about the differences from typical Python classes
is warranted:
- Enum members are virtual
- Enum members are singletons
- new Enum members (aka instances of an Enum class) cannot be created
- during class creation Enum
Ethan Furman added the comment:
As for the error messages (going in reverse order):
==
--> del cute_cat.name
Traceback (most recent call last):
...
AttributeError: can't delete a
Ethan Furman added the comment:
As David noted, this was discussed somewhere in the megathreads that was the
Enum PEP discussion.
As Georg noted changes to such a thoroughly discussed API should not be taken
lightly.
As Antoine noted the Enum class is more restricted than normal classes by
Ethan Furman added the comment:
Two issues still remain:
- custom behavior, as well as value and name, don't show in help
- value and name, if defined as enum members, show up as data
descriptors in
New submission from Ethan Furman:
Due to the odd nature of Enum classes and instances, the normal methods used by
inspect.getmembers and inspect.classify_class_attrs are insufficient.
By special casing Enum inside those two functions the correct information can
be returned.
Here is an
New submission from Ethan Furman:
Currently, if help() is called on an Enum member, it displays help for the
class. While this is usually what one wants, it is not for Enums.
--
messages: 197845
nosy: barry, eli.bendersky, ethan.furman
priority: normal
severity: normal
status: open
Ethan Furman added the comment:
Tracking inspect in issue19030.
Tracking help in issue19031.
--
___
Python tracker
<http://bugs.python.org/issue18693>
___
___
Ethan Furman added the comment:
Attached patch yields these results:
===
Help on class Test in module __main__:
class Test(enum.Enum)
| Method resolution order:
| Test
| enum.Enum
Ethan Furman added the comment:
R David Murray said:
>
>Special casing Enum in inspect has a code smell to it.
I agree, and I'm certainly open to other options.
The flow at this point is:
help() --> inspect.classify_class_attrs --> dir() --> Enum.__dir__
Because inspe
Ethan Furman added the comment:
I do not see one. I did post to PyDev asking about dir -- perhaps I should
have given it a different title.
--
___
Python tracker
<http://bugs.python.org/issue19
Ethan Furman added the comment:
Here's a crazy idea. :)
The only reason the patch is tied to Enum is because of Enum's use of the
_RouteClassAttributeToGetattr descriptor.
If we had a module similar to functools, say classtools, we could flesh out
_RouteClassAttributeToGetattr, re
Ethan Furman added the comment:
Switching the order to try getattr first is going to make getting the doc from
the descriptor problematic -- we have no way of knowing if the descriptor doc
goes with the object we got back from getattr.
Current patch adds VirtualAttribute to types, and reworks
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue1615>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue19040>
___
___
Python-bugs-list mailing list
Unsubscribe:
Ethan Furman added the comment:
Benjamin Peterson added the comment:
>
> I consider this to be a feature. Properties can raise AttributeError to defer
> to
> __getattr__.
Micah Friesen added the comment:
>
>I submit that this is not a feature - I can't imagine a real-wor
Ethan Furman added the comment:
Okay, some slight reorganizing. Current patch gives preferential treatment to
getattr, falling back on dict lookup if getattr raises an exception or if the
resulting object's class is not found in the mro (including the metaclass mro).
Amazingly, no
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue19075>
___
___
Python-bugs-list mailing list
Unsubscribe:
Ethan Furman added the comment:
Current patch has a little more code cleanup and a bunch more tests.
I copied and adapted test_property to test_VirtualAttribute, and
VirtualAttribute passes every test except the __slots__ test where __doc__ is
not supposed to copy. I think the problem there
Changes by Ethan Furman :
Added file: http://bugs.python.org/file31846/issue19030.stoneleaf.04.patch
___
Python tracker
<http://bugs.python.org/issue19030>
___
___
Pytho
Ethan Furman added the comment:
Okay, I changed my mind about __delattr__. Having it say "AttributeError:
cannot delete Enum member" is certainly nicer than "AttributeError: MemberName"
--
___
Python tracker
<http://bug
Ethan Furman added the comment:
Posted a message on PyDev, but unless I get feedback saying it's a bad idea, or
I find some implementation issue, I'll go ahead and make the change.
So either a doc patch or an enum patch will be
Ethan Furman added the comment:
How about this note after the AutoNumber example?
.. note::
The :meth:`__new__` method, if defined, is used during creation of the Enum
members; it is then replaced by Enum's :meth:`__new__` which is used after
class creation for lookup of exi
Ethan Furman added the comment:
Yup, just trying to add some explanation on how it currently works.
Drekin, I'm sure you've already figured this out, but for those who may read
this in the future: what you need is a helper function:
def OptionalEnum(value):
"could also
Ethan Furman added the comment:
As discussed on PyDev[1], Enum members are bonafide class attributes, as in
they show on the class, not on the instances.
Documentation patch attached.
[1] https://mail.python.org/pipermail/python-dev/2013-September/128874.html
--
stage: -> pa
Ethan Furman added the comment:
Doc patch is in #19011. I'll close this one when that one is closed.
--
___
Python tracker
<http://bugs.python.org/is
Ethan Furman added the comment:
Ctrl-D has never work for me on Windows either.
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue19
Changes by Ethan Furman :
--
resolution: -> fixed
stage: patch review -> committed/rejected
status: open -> closed
___
Python tracker
<http://bugs.python.or
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue19148>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Ethan Furman :
--
assignee: -> ethan.furman
nosy: +ethan.furman
stage: -> patch review
___
Python tracker
<http://bugs.python.org/issue19156>
___
__
Ethan Furman added the comment:
Thanks for catching that, Cliff.
--
___
Python tracker
<http://bugs.python.org/issue19156>
___
___
Python-bugs-list mailin
Ethan Furman added the comment:
=
class Boom:
def __dir__(self):
return ['BOOM']
def __getattr__(self, name):
if name =='BOOM':
return 42
return super().__geta
Ethan Furman added the comment:
What are the requirements (if any) to get something added to demos? If not
many, I'll spiffy up the code a bit (mostly make it go more than one round
without having to restart).
--
___
Python tracker
Ethan Furman added the comment:
What I'd really like to see is for help to be smart enough to pick up the
docstrings from instances if an instance has one.
--
___
Python tracker
<http://bugs.python.org/is
Ethan Furman added the comment:
Christian, do you mind if I get this patchd committed?
--
___
Python tracker
<http://bugs.python.org/issue18281>
___
___
Python-bug
Changes by Ethan Furman :
--
nosy: +ethan.furman
stage: -> patch review
___
Python tracker
<http://bugs.python.org/issue19201>
___
___
Python-bugs-list mai
Ethan Furman added the comment:
Sounds like we have a consensus. If no objections I'll commit in four or five
days (in time for the last alpha).
--
___
Python tracker
<http://bugs.python.org/is
Ethan Furman added the comment:
Cool, thanks!
I didn't want to step on any toes. :)
--
___
Python tracker
<http://bugs.python.org/issue18281>
___
___
Pytho
Changes by Ethan Furman :
--
nosy: ethan.furman
priority: normal
severity: normal
status: open
title: add inspect functions to
___
Python tracker
<http://bugs.python.org/issue19
New submission from Ethan Furman:
Currently we have
- inspect.getmembers
- inspect.classify_class_attrs
But they only return what dir() returns.
It is proposed that we add
- inspect.get_all_members
- inspect.classify_all_class_attrs
which will look at all the attributes returned by
Ethan Furman added the comment:
'None' is not an appropriate response to the "Where does this attribute come
from" question. For one, it's wrong. For two, it breaks help.
The current patch fixes that particular problem (as a last resort it walks the
mro lookin
Ethan Furman added the comment:
Nick Couphlan added the comment:
>
> No, __class__ on a descriptor has *NOTHING* to do with how it was
> looked up. It's the class of the *result*.
Which is why in most cases it's discarded as the home class. (I could easily
be saying this wr
Ethan Furman added the comment:
It would certainly be nice. We could do a dir() on the metaclass, discarding
anything either not in dir(type) or not dundered, or both.
--
___
Python tracker
<http://bugs.python.org/issue19
Ethan Furman added the comment:
That portion of classify_class_attrs now reads:
else:
homecls = getattr(get_obj, "__objclass__", None)
if homecls not in possible_bases:
# if the resulting object does not live somewhere in the
# mro, drop
Ethan Furman added the comment:
I'm not sure what you are talking about. Here's the code:
try:
if value in cls._value2member_map_:
return cls._value2member_map_[value]
except TypeError:
# not there, now do long search -- O(n) behavior
for
Ethan Furman added the comment:
Here's the current __eq__ method:
def __eq__(self, other):
if type(other) is self.__class__:
return self is other
return NotImplemented
It is, in fact, using identity and not value equality.
I'm thinking we should eit
Ethan Furman added the comment:
CliffM added the comment:
>
> Sorry -- I could have been clearer :
>
> The conditional:
>
> if member.value == value:
>
> Is redundant as the tests stand. If you comment it out -- everything works.
> So therefore we are missing a tes
Ethan Furman added the comment:
Updated and renamed the DynamicClassAttribute tests, and discovered that
classify_class_attrs is not handling instance portion correctly.
class Meta(type):
def __getattr__(self, name):
if name == 'ham':
re
Ethan Furman added the comment:
Discovered a problem with one of the tests, moved back to issue19030. The
__class__/__objclass__ is gone, the code is simpler.
When issue19030 is committed I think we can make a doc change to include
__objclass__ somewhere and close this one.
--
stage
Ethan Furman added the comment:
Updated tests now passing.
Will commit Thursday, or Friday at the latest.
--
stage: -> patch review
Added file: http://bugs.python.org/file32123/issue19030.stoneleaf.05.patch
___
Python tracker
&l
Ethan Furman added the comment:
Well, I would say it's half a coverage issue, half a guard against accidental
deletion of the if test. :)
--
___
Python tracker
<http://bugs.python.org/is
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue10757>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue10972>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue10614>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue16310>
___
___
Python-bugs-list mailing list
Unsubscribe:
Ethan Furman added the comment:
It was originally put in to help inspect.classify_class_attrs, but recent
subsequent changes (not yet committed, issue19030), make it unnecessary.
Whether or not it stays depends on the changes to inspect being committed.
--
assignee: -> ethan.fur
Ethan Furman added the comment:
Ronald, if you get a chance could you try your descriptor, without the
__objclass__ work around, with the latest patch in #19030?
--
___
Python tracker
<http://bugs.python.org/issue16
Changes by Ethan Furman :
--
nosy: +ethan.furman
resolution: invalid ->
stage: committed/rejected ->
status: closed -> open
___
Python tracker
<http://bugs.python.or
Ethan Furman added the comment:
Oops! Issue update error, I was just adding myself to nosy as it looked like
it was still open.
Re-closing.
--
resolution: -> invalid
stage: -> committed/rejected
status: open -> closed
___
Python track
Ethan Furman added the comment:
According to the docs[1]:
12.1.4. What can be pickled and unpickled?
The following types can be pickled:
- None, True, and False
- integers, floating point numbers, complex numbers
- strings, bytes, bytearrays
- tuples, lists, sets, and
Ethan Furman added the comment:
Yeah, that one line should say, "named functions defined at the top level of a
module".
The following three paragraphs do, however, mention "named" several times.
Sounds like a doc issue.
--
__
Ethan Furman added the comment:
The problem with a randam unique name is making sure you get the same random
unique name across different runs, different pythons, and different orders of
execution.
--
___
Python tracker
<http://bugs.python.
Ethan Furman added the comment:
>From the pickle docs:
=
Note that functions (built-in and user-defined) are pickled by “fully
qualified” name reference, not by value. This means that only the
function name is pickled, al
Ethan Furman added the comment:
Jesús Cea Avión added the comment:
>
> If at your "top level" (module) you do:
>
> """
> a = lambda x: 2*x
> """
>
> You don't have an anonymous function, but a function called "a".
Ethan Furman added the comment:
Well, attached patch doesn't segfault in debug mode, but the errors aren't any
better; in fact, I'd say their worse. Here's the current output from my test
script:
===
getter failed
Ethan Furman added the comment:
If anyone with more experience wants ownership, feel free to take it from me.
;) Otherwise I'll do my best to get this figured out in time for the beta.
--
assignee: -> ethan.furman
stage: ->
Changes by Ethan Furman :
--
assignee: -> ethan.furman
versions: +Python 3.4 -Python 2.7, Python 3.2
___
Python tracker
<http://bugs.python.org/iss
Changes by Ethan Furman :
--
keywords: +patch
Added file: http://bugs.python.org/file32155/issue19272.stoneleaf.01.patch
___
Python tracker
<http://bugs.python.org/issue19
Ethan Furman added the comment:
Where do we stand with this issue?
--
___
Python tracker
<http://bugs.python.org/issue17576>
___
___
Python-bugs-list mailin
Ethan Furman added the comment:
This has been fixed in #19030: every good object will have a home class;
non-good objects (the result of buggy __dir__, __getattribute__, or __getattr__
methods) will not be returned and so cannot confuse pydoc.
--
resolution: -> fixed
st
New submission from Ethan Furman:
Currently __objclass__ is only documented in a ten-year old PEP.
--
messages: 200190
nosy: eric.araujo, ethan.furman, ezio.melotti, georg.brandl
priority: normal
severity: normal
status: open
title: add __objclass__ to the docs
Ethan Furman added the comment:
Added some clarification to the docs to make it clearer that lambda functions
cannot be pickled.
Facundo [1], if you want to pursue being able to pickle lambda functions please
open an enhancement issue. Some of the questions that come to mind:
1) for a
Ethan Furman added the comment:
Given the rarity of singletons, I don't think changing pickle in that way is
appropriate. Besides, pickle protocol 2 and above don't have the problem.
--
___
Python tracker
<http://bugs.python.o
Ethan Furman added the comment:
Charles-François Natali added the comment:
>
> Ethan, you just broke all the buildbots: you're now officialy a core
> developer! ;-)
I was actually hoping to put off this particular honor for a
Ethan Furman added the comment:
Thanks, Charles-François!
The problem occurred when I tried to push the commit and was told there was
trailing white-space. Naturally I then ran the de-whitespacing tool which of
course removed the whitespace from those lines where you added the \x20s back
on
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue19331>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue19330>
___
___
Python-bugs-list mailing list
Unsubscribe:
Changes by Ethan Furman :
--
nosy: +ethan.furman
___
Python tracker
<http://bugs.python.org/issue12029>
___
___
Python-bugs-list mailing list
Unsubscribe:
901 - 1000 of 1868 matches
Mail list logo