This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Reduce the number of imports for functools
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: methane, rhettinger, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2017-09-26 03:51 by methane, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3757 merged methane, 2017-09-26 03:55
Messages (5)
msg302998 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-09-26 03:51
Makes `import functools` about 1.5 ms faster.

* heapq is used only when Counter.most_common(n).
* types and waakref is used only for singledispatch.

master:

import time:   - _functools 76 us (self 76 us)
import time:       - _operator 110 us (self 110 us)
import time:     - operator 469 us (self 359 us)
import time:     - keyword 174 us (self 174 us)
import time:       - _heapq 189 us (self 189 us)
import time:     - heapq 400 us (self 211 us)
import time:     - itertools 137 us (self 137 us)
import time:     - reprlib 231 us (self 231 us)
import time:     - _collections 142 us (self 142 us)
import time:   - collections 3006 us (self 1456 us)
import time:     - collections.abc 191 us (self 191 us)
import time:   - types 518 us (self 327 us)
import time:   - weakref 577 us (self 577 us)
import time: - functools 4903 us (self 729 us)

patched:

import time:   - _functools 74 us (self 74 us)
import time:       - _operator 100 us (self 100 us)
import time:     - operator 460 us (self 361 us)
import time:     - keyword 174 us (self 174 us)
import time:     - itertools 139 us (self 139 us)
import time:     - reprlib 226 us (self 226 us)
import time:     - _collections 85 us (self 85 us)
import time:   - collections 2593 us (self 1512 us)
import time: - functools 3369 us (self 703 us)
msg302999 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-26 04:43
Initially my patch for issue30152 included the change in collections. But it was removed on Raymond's request.
msg303002 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-09-26 05:02
Go ahead.
msg303366 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-09-29 22:40
An option for deferred imports would be to leave a comment at the top where the import would otherwise be.  Example:

# import types, weakref  # Deferred to single_dispatch()

This accomplishes the PEP8 purpose of making all dependencies of the module visible at the top.
msg303399 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2017-09-30 07:13
New changeset 9811e80fd0ed9d74c76a66f1dd4e4b8afa9e8f53 by INADA Naoki in branch 'master':
bpo-31581: Reduce the number of imports for functools (GH-3757)
https://github.com/python/cpython/commit/9811e80fd0ed9d74c76a66f1dd4e4b8afa9e8f53
History
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75762
2017-09-30 07:17:17methanesetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-09-30 07:13:04methanesetmessages: + msg303399
2017-09-29 22:40:18terry.reedysetnosy: + terry.reedy
messages: + msg303366
2017-09-26 05:02:10rhettingersetmessages: + msg303002
2017-09-26 04:43:12serhiy.storchakasetnosy: + rhettinger, serhiy.storchaka
messages: + msg302999
2017-09-26 03:55:13methanesetkeywords: + patch
stage: patch review
pull_requests: + pull_request3743
2017-09-26 03:51:59methanecreate