1
0
Fork 0
forked from github/pelican

Fixes in files for ruff T201, RUF001, PLR2004, B904, SLOT000, PYI024, PIE800

This commit is contained in:
boxydog 2024-05-31 10:41:24 -05:00
commit 82b48fcfa1
8 changed files with 18 additions and 20 deletions

View file

@ -29,7 +29,7 @@ source_suffix = ".rst"
master_doc = "index"
project = project_data.get("name").upper()
year = datetime.datetime.now().date().year
copyright = f"2010{year}"
copyright = f"2010{year}" # noqa: RUF001
exclude_patterns = ["_build"]
release = project_data.get("version")
version = ".".join(release.split(".")[:1])

View file

@ -294,7 +294,7 @@ class ParseOverrides(argparse.Action):
raise ValueError(
"Extra settings must be specified as KEY=VALUE pairs "
f"but you specified {item}"
)
) from None
try:
overrides[k] = json.loads(v)
except json.decoder.JSONDecodeError:
@ -305,7 +305,7 @@ class ParseOverrides(argparse.Action):
"Use -e KEY='\"string\"' to specify a string value; "
"-e KEY=null to specify None; "
"-e KEY=false (or true) to specify False (or True)."
)
) from None
setattr(namespace, self.dest, overrides)

View file

@ -1040,7 +1040,7 @@ class StaticGenerator(Generator):
save_as = os.path.join(self.output_path, staticfile.save_as)
s_mtime = os.path.getmtime(source_path)
d_mtime = os.path.getmtime(save_as)
return s_mtime - d_mtime > 0.000001
return s_mtime - d_mtime > 0.000001 # noqa: PLR2004
def _link_or_copy_staticfile(self, sc):
if self.settings["STATIC_CREATE_LINKS"]:

View file

@ -5,7 +5,7 @@ from collections import namedtuple
from math import ceil
logger = logging.getLogger(__name__)
PaginationRule = namedtuple(
PaginationRule = namedtuple( # noqa: PYI024
"PaginationRule",
"min_page URL SAVE_AS",
)

View file

@ -53,14 +53,12 @@ class ComplexHTTPRequestHandler(server.SimpleHTTPRequestHandler):
extensions_map = {
**server.SimpleHTTPRequestHandler.extensions_map,
**{
# web fonts
".oft": "font/oft",
".sfnt": "font/sfnt",
".ttf": "font/ttf",
".woff": "font/woff",
".woff2": "font/woff2",
},
# web fonts
".oft": "font/oft",
".sfnt": "font/sfnt",
".ttf": "font/ttf",
".woff": "font/woff",
".woff2": "font/woff2",
}
def translate_path(self, path):

View file

@ -376,7 +376,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
test_post = filter(lambda p: p[0].startswith("Post with raw data"), self.posts)
with temporary_folder() as temp:
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
escaped_quotes = re.search(r'\\[\'"“”‘’]', md)
escaped_quotes = re.search(r'\\[\'"“”‘’]', md) # noqa: RUF001
self.assertFalse(escaped_quotes)
def test_convert_caption_to_figure(self):
@ -505,7 +505,7 @@ class TestWordpressXMLAttachements(TestCaseWithCLocale):
def test_recognise_attachments(self):
self.assertTrue(self.attachments)
self.assertTrue(len(self.attachments.keys()) == 3)
self.assertEqual(3, len(self.attachments.keys()))
def test_attachments_associated_with_correct_post(self):
self.assertTrue(self.attachments)

View file

@ -79,7 +79,7 @@ _TZ_URL = "https://en.wikipedia.org/wiki/List_of_tz_database_time_zones"
# Create a 'marked' default path, to determine if someone has supplied
# a path on the command-line.
class _DEFAULT_PATH_TYPE(str):
class _DEFAULT_PATH_TYPE(str): # noqa: SLOT000
is_default_path = True

View file

@ -81,7 +81,7 @@ def strftime(date: datetime.datetime, date_format: str) -> str:
# test for valid C89 directives only
if candidate[-1] in c89_directives:
# check for '-' prefix
if len(candidate) == 3:
if len(candidate) == 3: # noqa: PLR2004
# '-' prefix
candidate = f"%{candidate[-1]}"
conversion = strip_zeros
@ -232,7 +232,7 @@ def get_date(string: str) -> datetime.datetime:
try:
return dateutil.parser.parse(string, default=default)
except (TypeError, ValueError):
raise ValueError(f"{string!r} is not a valid date")
raise ValueError(f"{string!r} is not a valid date") from None
@contextmanager
@ -666,13 +666,13 @@ def process_translations(
raise TypeError(
f"Cannot unpack {translation_id}, 'translation_id' must be falsy, a"
" string or a collection of strings"
)
) from None
except AttributeError:
raise AttributeError(
f"Cannot use {translation_id} as 'translation_id', there "
"appear to be items without these metadata "
"attributes"
)
) from None
for id_vals, items in groupby(content_list, attrgetter(*translation_id)):
# prepare warning string