Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf2f76e

Browse filesBrowse files
authored
bpo-41364: Reduce import overhead of uuid module (GH-21586)
1 parent 5241e18 commit bf2f76e
Copy full SHA for bf2f76e

File tree

2 files changed

+10
-7
lines changed
Filter options

2 files changed

+10
-7
lines changed

‎Lib/uuid.py

Copy file name to clipboardExpand all lines: Lib/uuid.py
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"""
4646

4747
import os
48-
import platform
4948
import sys
5049

5150
from enum import Enum
@@ -54,10 +53,13 @@
5453
__author__ = 'Ka-Ping Yee <ping@zesty.ca>'
5554

5655
# The recognized platforms - known behaviors
57-
_AIX = platform.system() == 'AIX'
58-
_DARWIN = platform.system() == 'Darwin'
59-
_LINUX = platform.system() == 'Linux'
60-
_WINDOWS = platform.system() == 'Windows'
56+
if sys.platform in ('win32', 'darwin'):
57+
_AIX = _LINUX = False
58+
else:
59+
import platform
60+
_platform_system = platform.system()
61+
_AIX = _platform_system == 'AIX'
62+
_LINUX = _platform_system == 'Linux'
6163

6264
_MAC_DELIM = b':'
6365
_MAC_OMITS_LEADING_ZEROES = False
@@ -618,9 +620,9 @@ def _random_getnode():
618620
# @unittest.skipUnless(_uuid._ifconfig_getnode in _uuid._GETTERS, ...)
619621
if _LINUX:
620622
_OS_GETTERS = [_ip_getnode, _ifconfig_getnode]
621-
elif _DARWIN:
623+
elif sys.platform == 'darwin':
622624
_OS_GETTERS = [_ifconfig_getnode, _arp_getnode, _netstat_getnode]
623-
elif _WINDOWS:
625+
elif sys.platform == 'win32':
624626
# bpo-40201: _windll_getnode will always succeed, so these are not needed
625627
_OS_GETTERS = []
626628
elif _AIX:
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduce import overhead of :mod:`uuid`.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.