Enable various ruff rules
This commit enables a bunch of unrelated ruff rules, which only require minimal changes to the code base to enable them. The rules enabled by this commit are: - check the use of datetime objects without timezone (DTZ005) - check the performance of try-except in loops (PERF203) - check the number of function arguments (PLR0913) - check for mutable class defaults (RUF012) - check for the use of secure hashing algorithms (S324) - check for raising base exceptions (TRY002) - check for raising other exceptions where TypeErrors should be raised (TRY004)
This commit is contained in:
parent
c0232c6b5f
commit
0ea6d32fa5
10
ruff.toml
10
ruff.toml
@ -12,36 +12,29 @@ ignore = [
|
|||||||
"C90",
|
"C90",
|
||||||
"COM812",
|
"COM812",
|
||||||
"D10",
|
"D10",
|
||||||
"DTZ005",
|
|
||||||
"EM",
|
"EM",
|
||||||
"FA",
|
"FA",
|
||||||
"FIX",
|
"FIX",
|
||||||
"FBT",
|
"FBT",
|
||||||
"ISC001",
|
"ISC001",
|
||||||
"N817",
|
"N817",
|
||||||
"PERF203",
|
|
||||||
"PERF401",
|
"PERF401",
|
||||||
"PLR0912",
|
"PLR0912",
|
||||||
"PLR0913",
|
|
||||||
"PLR0915",
|
"PLR0915",
|
||||||
"PLR2004",
|
"PLR2004",
|
||||||
"PLW2901",
|
"PLW2901",
|
||||||
"PT",
|
"PT",
|
||||||
"PTH",
|
"PTH",
|
||||||
"RUF012",
|
|
||||||
"S101",
|
"S101",
|
||||||
"S310",
|
"S310",
|
||||||
"S314",
|
"S314",
|
||||||
"S324",
|
|
||||||
"S320",
|
"S320",
|
||||||
"S603",
|
"S603",
|
||||||
"S607",
|
"S607",
|
||||||
"T20",
|
"T20",
|
||||||
"TD002",
|
"TD002",
|
||||||
"TD003",
|
"TD003",
|
||||||
"TRY002",
|
|
||||||
"TRY003",
|
"TRY003",
|
||||||
"TRY004",
|
|
||||||
"UP038",
|
"UP038",
|
||||||
"W505"
|
"W505"
|
||||||
]
|
]
|
||||||
@ -54,3 +47,6 @@ max-doc-length = 72
|
|||||||
|
|
||||||
[lint.pydocstyle]
|
[lint.pydocstyle]
|
||||||
convention = "pep257"
|
convention = "pep257"
|
||||||
|
|
||||||
|
[lint.pylint]
|
||||||
|
max-args = 8
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
# Adapted from http://cairographics.org/freetypepython/
|
# Adapted from http://cairographics.org/freetypepython/
|
||||||
|
|
||||||
|
# ruff: noqa: TRY002
|
||||||
|
|
||||||
import ctypes
|
import ctypes
|
||||||
import sys
|
import sys
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
@ -40,7 +43,7 @@ _surface = cairo.ImageSurface(cairo.FORMAT_A8, 0, 0)
|
|||||||
|
|
||||||
|
|
||||||
class PycairoContext(ctypes.Structure):
|
class PycairoContext(ctypes.Structure):
|
||||||
_fields_ = [
|
_fields_: ClassVar = [
|
||||||
("PyObject_HEAD", ctypes.c_byte * object.__basicsize__),
|
("PyObject_HEAD", ctypes.c_byte * object.__basicsize__),
|
||||||
("ctx", ctypes.c_void_p),
|
("ctx", ctypes.c_void_p),
|
||||||
("base", ctypes.c_void_p),
|
("base", ctypes.c_void_p),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Wrapper around babel Catalog / .po handling."""
|
"""Wrapper around babel Catalog / .po handling."""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import UTC, datetime
|
||||||
|
|
||||||
from babel.messages.catalog import Catalog as BabelCatalog
|
from babel.messages.catalog import Catalog as BabelCatalog
|
||||||
from babel.messages.pofile import read_po, write_po
|
from babel.messages.pofile import read_po, write_po
|
||||||
@ -10,7 +10,7 @@ class Catalog(BabelCatalog):
|
|||||||
"""Wraps a BabelCatalog for convenience."""
|
"""Wraps a BabelCatalog for convenience."""
|
||||||
|
|
||||||
def __init__(self, *args, project=None, copyright_holder=None, **other_kwargs):
|
def __init__(self, *args, project=None, copyright_holder=None, **other_kwargs):
|
||||||
date = datetime.now()
|
date = datetime.now(tz=UTC)
|
||||||
super().__init__(
|
super().__init__(
|
||||||
*args,
|
*args,
|
||||||
header_comment=(
|
header_comment=(
|
||||||
|
@ -46,7 +46,7 @@ def execute(command):
|
|||||||
def calculate_hash(path):
|
def calculate_hash(path):
|
||||||
assert os.path.isfile(path)
|
assert os.path.isfile(path)
|
||||||
with open(path, "rb") as handle:
|
with open(path, "rb") as handle:
|
||||||
return hashlib.sha1(handle.read()).hexdigest()
|
return hashlib.sha256(handle.read()).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def resolve_if(defines, expression):
|
def resolve_if(defines, expression):
|
||||||
|
@ -201,7 +201,7 @@ class RelaxNGValidator:
|
|||||||
try:
|
try:
|
||||||
doc = lxml.etree.parse(str(file[1]))
|
doc = lxml.etree.parse(str(file[1]))
|
||||||
relaxng.assertValid(doc)
|
relaxng.assertValid(doc)
|
||||||
except Exception:
|
except (lxml.etree.DocumentInvalid, lxml.etree.XMLSyntaxError):
|
||||||
error_count = error_count + 1
|
error_count = error_count + 1
|
||||||
self.logger.exception(file[1])
|
self.logger.exception(file[1])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user