classification
Title: Import collections ABC from collections.abc rather than collections
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: rhettinger, serhiy.storchaka, skrah, stutzbach, terry.reedy
Priority: normal Keywords:

Created on 2017-04-23 12:30 by serhiy.storchaka, last changed 2017-06-11 10:14 by terry.reedy. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1263 merged serhiy.storchaka, 2017-04-23 12:32
PR 2106 merged terry.reedy, 2017-06-11 09:46
Messages (7)
msg292164 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-23 12:30
Now abstract collection classes are defined in collections.abc rather than collections. collections contains just aliases for compatibility. Importing collections ABC from collections.abc is more idiomatic. And when aliases will be removed from collection this will be the only way.

But some code still imports them from collections. Proposed patch makes it importing them from collections.abc.

The most basic modules like locale, weakref and pathlib could import them just from _collections_abc for decreasing the startup time, but this is different issue.

The patch doesn't touch the collections module itself and its tests, and the _decimal module which imports collections.MutableMapping in C code (changing this would require more rewriting).
msg292165 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-04-23 12:59
I thought splitting off abc was done for performance reasons (reduce the number of imports at Python startup), not for more idiomatic code.
msg292166 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-23 13:32
If this is the main cause I can replace collections.abc in this patch with _collections_abc. But I prefer to do this in separate commit. My next patch will include other changes for the number of imports.
msg292171 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-04-23 16:21
+1 This patch looks like a step in the right direction.
msg292195 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-24 06:05
New changeset 2e576f5aec1f8f23f07001e2eb3db9276851a4fc by Serhiy Storchaka in branch 'master':
bpo-30144: Import collections ABC from collections.abc rather than collections. (#1263)
https://github.com/python/cpython/commit/2e576f5aec1f8f23f07001e2eb3db9276851a4fc
msg292202 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-24 07:41
Issue30152 replaces some collections.abc with _collections_abc for performance reasons.
msg295697 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-06-11 10:12
New changeset a13225e209cfa5f7b458dbcbac19dc4df26feb95 by terryjreedy in branch '3.6':
[3.6]bpo-30144: change idlelib abc import [GH-1263] (#2106)
https://github.com/python/cpython/commit/a13225e209cfa5f7b458dbcbac19dc4df26feb95
History
Date User Action Args
2017-06-11 10:14:03terry.reedysetassignee: terry.reedy
versions: + Python 3.6
2017-06-11 10:12:33terry.reedysetnosy: + terry.reedy
messages: + msg295697
2017-06-11 09:46:35terry.reedysetpull_requests: + pull_request2159
2017-04-24 07:41:43serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg292202

stage: patch review -> resolved
2017-04-24 06:05:02serhiy.storchakasetmessages: + msg292195
2017-04-23 16:21:07rhettingersetmessages: + msg292171
2017-04-23 13:32:46serhiy.storchakasetmessages: + msg292166
2017-04-23 12:59:15skrahsetnosy: + skrah
messages: + msg292165
2017-04-23 12:32:03serhiy.storchakasetpull_requests: + pull_request1376
2017-04-23 12:30:13serhiy.storchakacreate