From 44d5b64ba3a0375526928632af8450208096c79d Mon Sep 17 00:00:00 2001 From: mayeut Date: Mon, 31 Jul 2023 09:39:24 +0200 Subject: [PATCH] use PY3 Signed-off-by: mayeut --- psutil/__init__.py | 2 +- psutil/_common.py | 7 ++++--- psutil/_pslinux.py | 2 +- psutil/_psposix.py | 2 +- psutil/_pswindows.py | 2 +- psutil/tests/__init__.py | 2 +- psutil/tests/test_contracts.py | 4 ++-- psutil/tests/test_system.py | 3 ++- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/psutil/__init__.py b/psutil/__init__.py index 7e36e4fb6e..2b15670658 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -2189,7 +2189,7 @@ def net_if_addrs(): Note: you can have more than one address of the same family associated with each interface. """ - has_enums = sys.version_info[0] >= 3 + has_enums = _PY3 if has_enums: import socket rawlist = _psplatform.net_if_addrs() diff --git a/psutil/_common.py b/psutil/_common.py index b9049e63a4..a0d49d6384 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -35,14 +35,15 @@ except ImportError: AF_UNIX = None -if sys.version_info[0] >= 3: + +# can't take it from _common.py as this script is imported by setup.py +PY3 = sys.version_info[0] == 3 +if PY3: import enum else: enum = None -# can't take it from _common.py as this script is imported by setup.py -PY3 = sys.version_info[0] == 3 PSUTIL_DEBUG = bool(os.getenv('PSUTIL_DEBUG')) _DEFAULT = object() diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index aaee9df86e..e0acb0e297 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -53,7 +53,7 @@ from ._compat import basestring -if sys.version_info[0] >= 3: +if PY3: import enum else: enum = None diff --git a/psutil/_psposix.py b/psutil/_psposix.py index 4cc63439c4..0039daf44a 100644 --- a/psutil/_psposix.py +++ b/psutil/_psposix.py @@ -28,7 +28,7 @@ from . import _psutil_osx -if sys.version_info[0] >= 3: +if PY3: import enum else: enum = None diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index eeabc81feb..eec2db84db 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -56,7 +56,7 @@ else: raise -if sys.version_info[0] >= 3: +if PY3: import enum else: enum = None diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 51b6279796..0781f06862 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -67,7 +67,7 @@ warnings.simplefilter("ignore") import mock # NOQA - requires "pip install mock" -if sys.version_info[0] >= 3: +if PY3: import enum else: enum = None diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py index b1a5af5665..e0bb92ce56 100755 --- a/psutil/tests/test_contracts.py +++ b/psutil/tests/test_contracts.py @@ -15,7 +15,6 @@ import platform import signal import stat -import sys import time import traceback import unittest @@ -36,6 +35,7 @@ from psutil._compat import long from psutil._compat import range from psutil._compat import unicode +from psutil._compat import PY3 from psutil.tests import APPVEYOR from psutil.tests import CI_TESTING from psutil.tests import GITHUB_ACTIONS @@ -723,7 +723,7 @@ def nice(self, ret, info): priorities = [getattr(psutil, x) for x in dir(psutil) if x.endswith('_PRIORITY_CLASS')] self.assertIn(ret, priorities) - if sys.version_info[0] >= 3: + if PY3: self.assertIsInstance(ret, enum.IntEnum) else: self.assertIsInstance(ret, int) diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index aba88be8d6..3f96762947 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -32,6 +32,7 @@ from psutil import WINDOWS from psutil._compat import FileNotFoundError from psutil._compat import long +from psutil._compat import PY3 from psutil.tests import ASCII_FS from psutil.tests import CI_TESTING from psutil.tests import DEVNULL @@ -751,7 +752,7 @@ def test_net_if_addrs(self): self.assertIsInstance(addr.netmask, (str, type(None))) self.assertIsInstance(addr.broadcast, (str, type(None))) self.assertIn(addr.family, families) - if sys.version_info[0] >= 3 and not PYPY: + if PY3 and not PYPY: self.assertIsInstance(addr.family, enum.IntEnum) if nic_stats[nic].isup: # Do not test binding to addresses of interfaces