psf / pyperf

Toolkit to run Python benchmarks
http://pyperf.readthedocs.io/
MIT License
771 stars 74 forks source link

Add some ruff rules for pyupgrade #183

Closed cclauss closed 3 months ago

cclauss commented 3 months ago

% ruff check --select=UP --ignore=UP015,UP031 --statistics | sort -k2

10  UP004   [*] Class `BaseTestCase` inherits from `object`
 1  UP009   [*] UTF-8 encoding declaration is unnecessary
 1  UP020   [*] Use builtin `open`
18  UP024   [*] Replace aliased errors with `OSError`
 9  UP025   [*] Remove unicode literals from strings

% ruff rule UP024

os-error-alias (UP024)

Derived from the pyupgrade linter.

Fix is always available.

What it does

Checks for uses of exceptions that alias OSError.

Why is this bad?

OSError is the builtin error type used for exceptions that relate to the operating system.

In Python 3.3, a variety of other exceptions, like WindowsError were aliased to OSError. These aliases remain in place for compatibility with older versions of Python, but may be removed in future versions.

Prefer using OSError directly, as it is more idiomatic and future-proof.

Example

raise IOError

Use instead:

raise OSError

References

corona10 commented 3 months ago

If you want to submit the patch related code style issue, would you like to submit the patch including the CI works? cc @vstinner

vstinner commented 3 months ago

@cclauss cclauss closed

This change combines many different changes. Some of them are uncontroversial, I have an opinion on the others :-)

cclauss commented 3 months ago

I understand.

These PRs are super easy to create locally with syntax like: % ruff check --select=UP004 --fix

vstinner commented 3 months ago

I'm fine with these changes, coming from the old time when pyperf worked on Python 2:

10  UP004   [*] Class `BaseTestCase` inherits from `object`
 1  UP009   [*] UTF-8 encoding declaration is unnecessary
 1  UP020   [*] Use builtin `open`
18  UP024   [*] Replace aliased errors with `OSError`
 9  UP025   [*] Remove unicode literals from strings
vstinner commented 3 months ago

Merged, thanks.