From bf2f76ec0976c09de79c8827764f30e3b6fba776 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 22 Jul 2020 00:15:47 +0100 Subject: bpo-41364: Reduce import overhead of uuid module (GH-21586) --- Lib/uuid.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'Lib/uuid.py') diff --git a/Lib/uuid.py b/Lib/uuid.py index 9ddce813fc..5ae0a3e5fa 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -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 ' # 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' _MAC_DELIM = b':' _MAC_OMITS_LEADING_ZEROES = False @@ -618,9 +620,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': # bpo-40201: _windll_getnode will always succeed, so these are not needed _OS_GETTERS = [] elif _AIX: -- cgit v1.2.1