Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some ruff rules for pyupgrade #183

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# pyperf documentation build configuration file, created by
# sphinx-quickstart on Wed Jun 1 15:28:03 2016.
Expand Down Expand Up @@ -42,9 +41,9 @@
master_doc = 'index'

# General information about the project.
project = u'pyperf'
copyright = u'2016, Victor Stinner'
author = u'Victor Stinner'
project = 'pyperf'
copyright = '2016, Victor Stinner'
author = 'Victor Stinner'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -216,8 +215,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pyperf.tex', u'pyperf Documentation',
u'Victor Stinner', 'manual'),
(master_doc, 'pyperf.tex', 'pyperf Documentation',
'Victor Stinner', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -246,7 +245,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pyperf', u'pyperf Documentation',
(master_doc, 'pyperf', 'pyperf Documentation',
[author], 1)
]

Expand All @@ -260,7 +259,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pyperf', u'pyperf Documentation',
(master_doc, 'pyperf', 'pyperf Documentation',
author, 'pyperf', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
10 changes: 5 additions & 5 deletions pyperf/_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def method(self):
return method


class Run(object):
class Run:
# Run is immutable, so it can be shared/exchanged between two benchmarks

__slots__ = ('_warmups', '_values', '_metadata')
Expand Down Expand Up @@ -319,7 +319,7 @@ def _update_metadata(self, metadata):
return self._replace(metadata=metadata2)


class Benchmark(object):
class Benchmark:
def __init__(self, runs):
self._runs = [] # list of Run objects
self._clear_runs_cache()
Expand Down Expand Up @@ -627,7 +627,7 @@ def update_metadata(self, metadata):
self._replace_runs(new_runs)


class BenchmarkSuite(object):
class BenchmarkSuite:
def __init__(self, benchmarks, filename=None):
if not benchmarks:
raise ValueError("benchmarks must be a non-empty "
Expand Down Expand Up @@ -727,7 +727,7 @@ def _load_open(filename):
if isinstance(filename, bytes):
suffix = b'.gz'
else:
suffix = u'.gz'
suffix = '.gz'

if filename.endswith(suffix):
# Use lazy import to limit imports on 'import pyperf'
Expand Down Expand Up @@ -770,7 +770,7 @@ def _dump_open(filename, replace):
if isinstance(filename, bytes):
suffix = b'.gz'
else:
suffix = u'.gz'
suffix = '.gz'

if not replace and os.path.exists(filename):
raise OSError(errno.EEXIST, "File already exists")
Expand Down
4 changes: 2 additions & 2 deletions pyperf/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def catch_broken_pipe_error(file=None):
# was closed by the consumer
for file in files:
file.flush()
except IOError as exc:
except OSError as exc:
if exc.errno != errno.EPIPE:
raise
# got a broken pipe error: ignore it
Expand All @@ -615,5 +615,5 @@ def catch_broken_pipe_error(file=None):
for file in files:
try:
file.close()
except IOError:
except OSError:
pass
4 changes: 2 additions & 2 deletions pyperf/_collect_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def read_proc(path):
with open_text(path) as fp:
for line in fp:
yield line.rstrip()
except (OSError, IOError):
except OSError:
return


Expand Down Expand Up @@ -332,7 +332,7 @@ def get_cpu_temperature(path, cpu_temp):

try:
temp_label = read_first_line(template % 'label', error=True)
except IOError:
except OSError:
break

temp_input = read_first_line(template % 'input', error=True)
Expand Down
2 changes: 1 addition & 1 deletion pyperf/_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_tags_for_result(result):
return result.ref.benchmark.get_metadata().get("tags", [])


class CompareResult(object):
class CompareResult:
def __init__(self, ref, changed, min_speed=None):
# CompareData object
self.ref = ref
Expand Down
2 changes: 1 addition & 1 deletion pyperf/_linux_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def check_tracking_memory():
mem_thread = PeakMemoryUsageThread()
try:
mem_thread.get()
except IOError as exc:
except OSError as exc:
path = proc_path("self/smaps")
return "unable to read %s: %s" % (path, exc)

Expand Down
2 changes: 1 addition & 1 deletion pyperf/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
MAX_CALIBRATION = 5


class Manager(object):
class Manager:
"""
Manager process which spawns worker processes to:
- calibrate warmups
Expand Down
2 changes: 1 addition & 1 deletion pyperf/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def format_metadata(name, value):
return info.formatter(value)


class Metadata(object):
class Metadata:
def __init__(self, name, value):
self._name = name
self._value = value
Expand Down
22 changes: 11 additions & 11 deletions pyperf/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def use_intel_pstate():
return (scaling_driver == 'intel_pstate')


class Operation(object):
class Operation:
@staticmethod
def available():
return True
Expand Down Expand Up @@ -107,7 +107,7 @@ def check_permission_error(self, exc):
def read_first_line(self, path):
try:
return read_first_line(path, error=True)
except IOError as exc:
except OSError as exc:
self.check_permission_error(exc)
return ''

Expand Down Expand Up @@ -219,7 +219,7 @@ def write_msr(self, cpu, reg_num, value):
os.write(fd, data)
finally:
os.close(fd)
except IOError as exc:
except OSError as exc:
self.check_permission_error(exc)
self.error("Failed to write %#x into MSR %#x using %s: %s"
% (value, reg_num, path, exc))
Expand Down Expand Up @@ -308,7 +308,7 @@ def write(self, tune):
content = '0' if enable else '1'
try:
write_text(self.path, content)
except IOError as exc:
except OSError as exc:
# don't log a permission error if the user is root: permission
# error as root means that Turbo Boost is disabled in the BIOS
if not is_root():
Expand Down Expand Up @@ -376,7 +376,7 @@ def write(self, tune):
return
try:
write_text(self.path, new_governor)
except IOError as exc:
except OSError as exc:
self.error("Failed to set the CPU scaling governor: %s" % exc)
else:
self.log_action("CPU scaling governor set to %s" % new_governor)
Expand Down Expand Up @@ -495,7 +495,7 @@ def write(self, tune):

try:
write_text(self.path, new_value)
except IOError as exc:
except OSError as exc:
self.check_permission_error(exc)
self.error("Failed to write into %s: %s" % (self.path, exc))
else:
Expand Down Expand Up @@ -552,7 +552,7 @@ def read_freq(self, filename):
try:
with open(filename, "rb") as fp:
return fp.readline()
except IOError as exc:
except OSError as exc:
self.check_permission_error(exc)
return None

Expand All @@ -579,7 +579,7 @@ def write_cpu(self, cpu, tune):
filename = os.path.join(cpu_path, "scaling_min_freq")
try:
return self.write_freq(filename, freq)
except IOError as exc:
except OSError as exc:
self.check_permission_error(exc)
self.error("Unable to write scaling_max_freq of CPU %s: %s"
% (cpu, exc))
Expand Down Expand Up @@ -768,7 +768,7 @@ def write_default(self, new_affinity):
mask = format_cpus_as_mask(new_affinity)
try:
write_text(self.default_affinity_path, mask)
except IOError as exc:
except OSError as exc:
self.check_permission_error(exc)
self.error("Failed to write %r into %s: %s"
% (mask, self.default_affinity_path, exc))
Expand All @@ -782,7 +782,7 @@ def write_irq(self, irq, cpus):
try:
write_text(path, mask)
return True
except IOError as exc:
except OSError as exc:
self.check_permission_error(exc)
# EIO means that the IRQ doesn't support SMP affinity:
# ignore the error
Expand Down Expand Up @@ -937,7 +937,7 @@ def write(self, tune):

try:
write_text(self.path, str(new_rate))
except IOError as exc:
except OSError as exc:
self.check_permission_error(exc)
self.error("Failed to write into %s: %s" % (self.path, exc))
else:
Expand Down
4 changes: 2 additions & 2 deletions pyperf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def read_first_line(path, error=False):
with open_text(path) as fp:
line = fp.readline()
return line.rstrip()
except IOError:
except OSError:
if error:
raise
else:
Expand Down Expand Up @@ -282,7 +282,7 @@ def create_environ(inherit_environ, locale, copy_all):
return env


class _Pipe(object):
class _Pipe:
_OPEN_MODE = "r"

def __init__(self, fd):
Expand Down
2 changes: 1 addition & 1 deletion pyperf/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def temporary_directory():
def benchmark_as_json(benchmark, compact=True):
with temporary_file() as tmp_name:
benchmark.dump(tmp_name, compact=compact)
with io.open(tmp_name, 'r', encoding='utf-8') as tmp:
with open(tmp_name, 'r', encoding='utf-8') as tmp:
return tmp.read()


Expand Down
2 changes: 1 addition & 1 deletion pyperf/tests/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def get_raw_values(filename, run_id):
return (run, raw_values)


class Replay(object):
class Replay:
def __init__(self, runner, filename):
self.runner = runner
self.args = runner.args
Expand Down
4 changes: 2 additions & 2 deletions pyperf/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def mock_open(filename, *args, **kw):
elif filename.startswith('/sys/devices/system/cpu/nohz_full'):
data = nohz_full
elif filename.startswith('/sys/devices/system/cpu/cpu2'):
raise IOError
raise OSError
elif filename == '/sys/devices/system/cpu/cpuidle/current_driver':
data = 'IDLE_DRV\n'
else:
Expand Down Expand Up @@ -194,7 +194,7 @@ def mock_open(filename, *args, **kw):
elif filename == '/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor':
data = 'GOVERNOR\n'
elif filename.startswith('/sys/devices/system/cpu/cpu2'):
raise IOError
raise OSError
else:
raise ValueError("unexpect open: %r" % filename)
return io.StringIO(data)
Expand Down
2 changes: 1 addition & 1 deletion pyperf/tests/test_perf_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
TELCO = os.path.join(TESTDIR, 'telco.json')


class BaseTestCase(object):
class BaseTestCase:
maxDiff = 100 * 80

def create_bench(self, values, metadata=None):
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ packages = ["pyperf", "pyperf.tests"]

[tool.setuptools.dynamic]
version = {attr = "pyperf.__version__"}

[tool.ruff.lint]
extend-select = ["C90", "UP"]
extend-ignore = ["UP015", "UP031"]

[tool.ruff.lint.mccabe]
max-complexity = 31
Loading