Skip to content

Commit a18f22a

Browse files
authored
bpo-41364: Reduce import overhead of uuid module (GH-21586)
1 parent f599f9e commit a18f22a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Lib/uuid.py

+9-7
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 <[email protected]>'
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
RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [
6365
'reserved for NCS compatibility', 'specified in RFC 4122',
@@ -688,9 +690,9 @@ def _random_getnode():
688690
# @unittest.skipUnless(_uuid._ifconfig_getnode in _uuid._GETTERS, ...)
689691
if _LINUX:
690692
_OS_GETTERS = [_ip_getnode, _ifconfig_getnode]
691-
elif _DARWIN:
693+
elif sys.platform == 'darwin':
692694
_OS_GETTERS = [_ifconfig_getnode, _arp_getnode, _netstat_getnode]
693-
elif _WINDOWS:
695+
elif sys.platform == 'win32':
694696
_OS_GETTERS = [_netbios_getnode, _ipconfig_getnode]
695697
elif _AIX:
696698
_OS_GETTERS = [_netstat_getnode]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduce import overhead of :mod:`uuid`.

0 commit comments

Comments
 (0)