Skip to content

Commit

Permalink
Run pyupgrade --py36-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Jan 28, 2024
1 parent 1fb97db commit 82dd9f9
Show file tree
Hide file tree
Showing 46 changed files with 157 additions and 195 deletions.
11 changes: 4 additions & 7 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand All @@ -20,7 +18,6 @@
Works with Python versions 3.6+.
"""

from __future__ import division

import collections
import contextlib
Expand Down Expand Up @@ -281,7 +278,7 @@ def _pprint_secs(secs):
# =====================================================================


class Process(object): # noqa: UP004
class Process:
"""Represents an OS process with the given PID.
If PID is omitted current process PID (os.getpid()) is used.
Raise NoSuchProcess if PID does not exist.
Expand Down Expand Up @@ -389,7 +386,7 @@ def __str__(self):
info["exitcode"] = self._exitcode
if self._create_time is not None:
info['started'] = _pprint_secs(self._create_time)
return "%s.%s(%s)" % (
return "{}.{}({})".format(
self.__class__.__module__,
self.__class__.__name__,
", ".join(["%s=%r" % (k, v) for k, v in info.items()]),
Expand Down Expand Up @@ -1410,7 +1407,7 @@ def __getattribute__(self, name):
def wait(self, timeout=None):
if self.__subproc.returncode is not None:
return self.__subproc.returncode
ret = super(Popen, self).wait(timeout) # noqa
ret = super().wait(timeout)
self.__subproc.returncode = ret
return ret

Expand Down Expand Up @@ -2475,7 +2472,7 @@ def test(): # pragma: no cover
print(line[: get_terminal_size()[0]]) # NOQA


del memoize_when_activated, division
del memoize_when_activated


if __name__ == "__main__":
Expand Down
12 changes: 5 additions & 7 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# Note: this module is imported by setup.py so it should not import
# psutil or third-party modules.

from __future__ import division
from __future__ import print_function

import collections
import contextlib
Expand Down Expand Up @@ -296,8 +294,8 @@ def __str__(self):
def __repr__(self):
# invoked on `repr(Error)`
info = self._infodict(("pid", "ppid", "name", "seconds", "msg"))
details = ", ".join(["%s=%r" % (k, v) for k, v in info.items()])
return "psutil.%s(%s)" % (self.__class__.__name__, details)
details = ", ".join([f"{k}={v!r}" for k, v in info.items()])
return f"psutil.{self.__class__.__name__}({details})"


class NoSuchProcess(Error):
Expand Down Expand Up @@ -545,7 +543,7 @@ def supports_ipv6():
with contextlib.closing(sock):
sock.bind(("::1", 0))
return True
except socket.error:
except OSError:
return False


Expand Down Expand Up @@ -798,7 +796,7 @@ def cat(fname, fallback=_DEFAULT, _open=open_text):
try:
with _open(fname) as f:
return f.read()
except (IOError, OSError):
except OSError:
return fallback


Expand Down Expand Up @@ -882,7 +880,7 @@ def hilite(s, color=None, bold=False): # pragma: no cover
attr.append(color)
if bold:
attr.append('1')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), s)
return '\x1b[{}m{}\x1b[0m'.format(';'.join(attr), s)


def print_color(
Expand Down
12 changes: 6 additions & 6 deletions psutil/_psaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def cpu_count_cores():
x.decode(sys.stdout.encoding) for x in (stdout, stderr)
)
if p.returncode != 0:
raise RuntimeError("%r command error\n%s" % (cmd, stderr))
raise RuntimeError(f"{cmd!r} command error\n{stderr}")
processors = stdout.strip().splitlines()
return len(processors) or None

Expand Down Expand Up @@ -441,7 +441,7 @@ def threads(self):
# is no longer there.
if not retlist:
# will raise NSP if process is gone
os.stat('%s/%s' % (self._procfs_path, self.pid))
os.stat(f'{self._procfs_path}/{self.pid}')
return retlist

@wrap_exceptions
Expand All @@ -454,7 +454,7 @@ def connections(self, kind='inet'):
# is no longer there.
if not ret:
# will raise NSP if process is gone
os.stat('%s/%s' % (self._procfs_path, self.pid))
os.stat(f'{self._procfs_path}/{self.pid}')
return ret

@wrap_exceptions
Expand Down Expand Up @@ -500,10 +500,10 @@ def terminal(self):
def cwd(self):
procfs_path = self._procfs_path
try:
result = os.readlink("%s/%s/cwd" % (procfs_path, self.pid))
result = os.readlink(f"{procfs_path}/{self.pid}/cwd")
return result.rstrip('/')
except FileNotFoundError:
os.stat("%s/%s" % (procfs_path, self.pid)) # raise NSP or AD
os.stat(f"{procfs_path}/{self.pid}") # raise NSP or AD
return ""

@wrap_exceptions
Expand Down Expand Up @@ -550,7 +550,7 @@ def open_files(self):
def num_fds(self):
if self.pid == 0: # no /proc/0/fd
return 0
return len(os.listdir("%s/%s/fd" % (self._procfs_path, self.pid)))
return len(os.listdir(f"{self._procfs_path}/{self.pid}/fd"))

@wrap_exceptions
def num_ctx_switches(self):
Expand Down
Loading

0 comments on commit 82dd9f9

Please sign in to comment.