[issue25147] Enum: remove dependency on OrderedDict

2015-09-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

But the comment is false. That change doesn't reduce startup cost.

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-18 Thread Stefan Behnel

Stefan Behnel added the comment:

Let's say the change minimises the dependencies. That is a reasonable goal, too.

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Ethan Furman

Changes by Ethan Furman :


--
keywords: +patch
Added file: http://bugs.python.org/file40489/issue25147.stoneleaf.01.patch

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Ethan Furman

New submission from Ethan Furman:

Pulling in collections.OrderedDict has a significant startup cost (from what 
I've heard, and can easily believe by glancing at all the imports in 
collections.__init__).

By keeping a separate list for the Enum member names using Enum in the stdlib 
becomes more attractive.

--
assignee: ethan.furman
messages: 250875
nosy: barry, eli.bendersky, ethan.furman
priority: normal
severity: normal
stage: patch review
status: open
title: Enum: remove dependency on OrderedDict
versions: Python 3.6

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

This change has visible side effect: __members__ is no longer ordered. This 
should be reflected in the documentation and in What's New.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread STINNER Victor

STINNER Victor added the comment:

> This change has visible side effect: __members__ is no longer ordered.

This property of part of the PEP 435 (enum):
"The special attribute __members__ is an ordered dictionary mapping names to 
members."

IMHO if we really want to change this, it must be discussed on the python-dev 
mailing list.

To keep __members__ ordered, we can delay the creation of the OrderedDict at 
the first access to __members__: start with a dict, and use the ordered 
_all_member_names_ to created the ordered dictionary.

Attached patch implements this idea.

I checked enum.Enum and enum.IntEnum classes and the @enum.unique decorated: 
__members__ is not used to declare the class. Hum, I had to modify a little bit 
@enum.unique to not access __members__.

--
nosy: +haypo
Added file: http://bugs.python.org/file40490/delayed_ordered_dict.patch

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Ethan Furman

Ethan Furman added the comment:

Is pulling in `_collections` not as resource intensive as pulling in 
`collections`?

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Eric Snow

Eric Snow added the comment:

OrderedDict has a C implementation now.  So try the following:

try:
from _collections import OrderedDict
except ImportError:
from collections import OrderedDict

--
nosy: +eric.snow

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

_collections exists because it contains C implementations of some collections 
classes or helpers. _collections itself is imported only in collections and 
threading. And in threading the same idiom as proposed by Eric is used:

try:
from _collections import deque as _deque
except ImportError:
from collections import deque as _deque

What is the cost of importing OrderedDict at all? Ethan, can you provide any 
measurement results?

--
nosy: +rhettinger

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I tried to measure import time with different patches and didn't notice any 
difference.

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Ethan Furman

Ethan Furman added the comment:

In that case I'll go with _collections; if performance does become an issue 
with other pythons later we can add the caching property.

Thanks for all the insights.

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread R. David Murray

R. David Murray added the comment:

_collections exists because it contains only the stuff that is needed at python 
startup.  So it is loaded regardless, and thus is very cheap to import 
elsewhere :)

--
nosy: +r.david.murray

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Ethan Furman

Ethan Furman added the comment:

_collections sounds cool, but the flip side is any python without the C 
implemntation would still have the slower startup, right?

No, I don't have measurements -- just that I have heard importing collections 
can have an effect on startup time.

Of course, it's only a cost you pay once, so maybe it's not a big deal.

On the other hand, I could make __members__ a caching property that doesn't 
import OrderedDict until it is used, and not use it internally -- and I can't 
think of any reason why the stdlib would need to access __members__ itself.

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If there is no any evidences, we shouldn't change a code.

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Ethan Furman

Ethan Furman added the comment:

Serhiy, your objection is noted, thank you.

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Roundup Robot

Roundup Robot added the comment:

New changeset b77916d2d7cc by Ethan Furman in branch 'default':
Close issue25147: use C implementation of OrderedDict
https://hg.python.org/cpython/rev/b77916d2d7cc

--
nosy: +python-dev
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Zachary Ware

Zachary Ware added the comment:

That change could use a comment stating why it's doing things that way instead 
of the 'obvious' way.

--
nosy: +zach.ware

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Roundup Robot

Roundup Robot added the comment:

New changeset c0363f849624 by Ethan Furman in branch 'default':
Issue 25147: add reason for using _collections
https://hg.python.org/cpython/rev/c0363f849624

--

___
Python tracker 

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



[issue25147] Enum: remove dependency on OrderedDict

2015-09-17 Thread Stefan Behnel

Stefan Behnel added the comment:

> _collections sounds cool, but the flip side is any python without the C 
> implemntation would still have the slower startup, right?

I wouldn't bother too much with that, certainly not given the order we are 
talking about here. Jython's startup time is slowed down mostly by the JVM 
startup time anyway. And if you use PyPy then it's exactly because you do *not* 
care about the startup time but about performance improvements for long running 
code.

--
nosy: +scoder

___
Python tracker 

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