]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41364: Reduce import overhead of uuid module (GH-21586)
authorSteve Dower <steve.dower@python.org>
Wed, 22 Jul 2020 11:26:37 +0000 (12:26 +0100)
committerGitHub <noreply@github.com>
Wed, 22 Jul 2020 11:26:37 +0000 (12:26 +0100)
Lib/uuid.py
Misc/NEWS.d/next/Library/2020-07-21-21-45-55.bpo-41364.5O-k7A.rst [new file with mode: 0644]

index 188e16ba14e3723062fa7106983a634f9eaa7cca..9540c21e6569fff7e3b33e09005f8dbafab4289b 100644 (file)
@@ -45,7 +45,6 @@ Typical usage:
 """
 
 import os
-import platform
 import sys
 
 from enum import Enum
@@ -54,10 +53,13 @@ from enum import Enum
 __author__ = 'Ka-Ping Yee <ping@zesty.ca>'
 
 # The recognized platforms - known behaviors
-_AIX     = platform.system() == 'AIX'
-_DARWIN  = platform.system() == 'Darwin'
-_LINUX   = platform.system() == 'Linux'
-_WINDOWS = platform.system() == 'Windows'
+if sys.platform in ('win32', 'darwin'):
+    _AIX = _LINUX = False
+else:
+    import platform
+    _platform_system = platform.system()
+    _AIX     = _platform_system == 'AIX'
+    _LINUX   = _platform_system == 'Linux'
 
 RESERVED_NCS, RFC_4122, RESERVED_MICROSOFT, RESERVED_FUTURE = [
     'reserved for NCS compatibility', 'specified in RFC 4122',
@@ -688,9 +690,9 @@ def _random_getnode():
 #     @unittest.skipUnless(_uuid._ifconfig_getnode in _uuid._GETTERS, ...)
 if _LINUX:
     _OS_GETTERS = [_ip_getnode, _ifconfig_getnode]
-elif _DARWIN:
+elif sys.platform == 'darwin':
     _OS_GETTERS = [_ifconfig_getnode, _arp_getnode, _netstat_getnode]
-elif _WINDOWS:
+elif sys.platform == 'win32':
     _OS_GETTERS = [_netbios_getnode, _ipconfig_getnode]
 elif _AIX:
     _OS_GETTERS = [_netstat_getnode]
diff --git a/Misc/NEWS.d/next/Library/2020-07-21-21-45-55.bpo-41364.5O-k7A.rst b/Misc/NEWS.d/next/Library/2020-07-21-21-45-55.bpo-41364.5O-k7A.rst
new file mode 100644 (file)
index 0000000..f136e89
--- /dev/null
@@ -0,0 +1 @@
+Reduce import overhead of :mod:`uuid`.