Skip to content

Commit

Permalink
Fixes in files for ruff T201, RUF001, PLR2004, B904, SLOT000, PYI024,…
Browse files Browse the repository at this point in the history
… PIE800
  • Loading branch information
boxydog committed May 31, 2024
1 parent fc45791 commit 82b48fc
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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])
Expand Down
4 changes: 2 additions & 2 deletions pelican/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def __call__(self, parser, namespace, values, option_string=None):
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:
Expand All @@ -305,7 +305,7 @@ def __call__(self, parser, namespace, values, option_string=None):
"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)


Expand Down
2 changes: 1 addition & 1 deletion pelican/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ def _source_is_newer(self, staticfile):
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"]:
Expand Down
2 changes: 1 addition & 1 deletion pelican/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from math import ceil

logger = logging.getLogger(__name__)
PaginationRule = namedtuple(
PaginationRule = namedtuple( # noqa: PYI024
"PaginationRule",
"min_page URL SAVE_AS",
)
Expand Down
14 changes: 6 additions & 8 deletions pelican/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pelican/tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def r(f):
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):
Expand Down Expand Up @@ -505,7 +505,7 @@ def setUp(self):

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)
Expand Down
2 changes: 1 addition & 1 deletion pelican/tools/pelican_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

# 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


Expand Down
8 changes: 4 additions & 4 deletions pelican/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def strip_zeros(x):
# 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 82b48fc

Please sign in to comment.