Skip to content

Commit

Permalink
use PY3
Browse files Browse the repository at this point in the history
Signed-off-by: mayeut <[email protected]>
  • Loading branch information
mayeut committed Jul 31, 2023
1 parent 37a5ea4 commit 44d5b64
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from ._compat import basestring


if sys.version_info[0] >= 3:
if PY3:
import enum
else:
enum = None
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psposix.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from . import _psutil_osx


if sys.version_info[0] >= 3:
if PY3:
import enum
else:
enum = None
Expand Down
2 changes: 1 addition & 1 deletion psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
else:
raise

if sys.version_info[0] >= 3:
if PY3:
import enum
else:
enum = None
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import platform
import signal
import stat
import sys
import time
import traceback
import unittest
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 44d5b64

Please sign in to comment.