From 7208b2d5c67b22a7ea295d4c0d230d52769ddc03 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:37:51 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- myst_parser/_docs.py | 2 +- myst_parser/config/main.py | 3 +-- myst_parser/mdit_to_docutils/base.py | 15 +++++++-------- myst_parser/mdit_to_docutils/sphinx_.py | 6 ++---- myst_parser/mocking.py | 3 +-- myst_parser/parsers/docutils_.py | 6 +++--- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/myst_parser/_docs.py b/myst_parser/_docs.py index 41212e98..95c8314e 100644 --- a/myst_parser/_docs.py +++ b/myst_parser/_docs.py @@ -211,7 +211,7 @@ def run(self): :Name: `{name}` :Description: {content} :Arguments: {klass.required_arguments} required, {klass.optional_arguments} optional -:Content: {'yes' if klass.has_content else 'no'} +:Content: {"yes" if klass.has_content else "no"} :Options: """ if klass.option_spec: diff --git a/myst_parser/config/main.py b/myst_parser/config/main.py index 2b088b56..2366abc2 100644 --- a/myst_parser/config/main.py +++ b/myst_parser/config/main.py @@ -522,8 +522,7 @@ def merge_file_level( if "html_meta" in topmatter: warning( MystWarnings.MD_TOPMATTER, - "top-level 'html_meta' key is deprecated, " - "place under 'myst' key instead", + "top-level 'html_meta' key is deprecated, place under 'myst' key instead", ) updates["html_meta"] = topmatter["html_meta"] if "substitutions" in topmatter: diff --git a/myst_parser/mdit_to_docutils/base.py b/myst_parser/mdit_to_docutils/base.py index 3778dd31..a17b423c 100644 --- a/myst_parser/mdit_to_docutils/base.py +++ b/myst_parser/mdit_to_docutils/base.py @@ -976,8 +976,7 @@ def render_link_path(self, token: SyntaxTreeNode) -> None: def render_link_project(self, token: SyntaxTreeNode) -> None: """Render a link token like ``.""" destination = cast(str, token.attrGet("href") or "") - if destination.startswith("project:"): - destination = destination[8:] + destination = destination.removeprefix("project:") if destination.startswith("#"): return self.render_link_anchor(token, destination) self.create_warning( @@ -1796,13 +1795,13 @@ def run_directive( ) return [error_msg] - assert isinstance( - result, list - ), f'Directive "{name}" must return a list of nodes.' + assert isinstance(result, list), ( + f'Directive "{name}" must return a list of nodes.' + ) for i in range(len(result)): - assert isinstance( - result[i], nodes.Node - ), f'Directive "{name}" returned non-Node object (index {i}): {result[i]}' + assert isinstance(result[i], nodes.Node), ( + f'Directive "{name}" returned non-Node object (index {i}): {result[i]}' + ) return result def render_substitution_inline(self, token: SyntaxTreeNode) -> None: diff --git a/myst_parser/mdit_to_docutils/sphinx_.py b/myst_parser/mdit_to_docutils/sphinx_.py index b9b29225..1569131f 100644 --- a/myst_parser/mdit_to_docutils/sphinx_.py +++ b/myst_parser/mdit_to_docutils/sphinx_.py @@ -72,8 +72,7 @@ def _handle_relative_docs(self, destination: str) -> str: def render_link_project(self, token: SyntaxTreeNode) -> None: destination = cast(str, token.attrGet("href") or "") - if destination.startswith("project:"): - destination = destination[8:] + destination = destination.removeprefix("project:") if destination.startswith("#"): return self.render_link_anchor(token, destination) @@ -108,8 +107,7 @@ def render_link_project(self, token: SyntaxTreeNode) -> None: def render_link_path(self, token: SyntaxTreeNode) -> None: destination = self.md.normalizeLinkText(cast(str, token.attrGet("href") or "")) - if destination.startswith("path:"): - destination = destination[5:] + destination = destination.removeprefix("path:") destination = self._handle_relative_docs(destination) explicit = (token.info != "auto") and (len(token.children or []) > 0) wrap_node = addnodes.download_reference( diff --git a/myst_parser/mocking.py b/myst_parser/mocking.py index 61a2b172..8a800bcc 100644 --- a/myst_parser/mocking.py +++ b/myst_parser/mocking.py @@ -461,8 +461,7 @@ def run(self) -> list[nodes.Element]: 3, ":number-lines: with non-integer start value" ) from err endline = startline + len(file_content.splitlines()) - if file_content.endswith("\n"): - file_content = file_content[:-1] + file_content = file_content.removesuffix("\n") tokens = NumberLines([([], file_content)], startline, endline) for classes, value in tokens: if classes: diff --git a/myst_parser/parsers/docutils_.py b/myst_parser/parsers/docutils_.py index e17de44b..a1a42407 100644 --- a/myst_parser/parsers/docutils_.py +++ b/myst_parser/parsers/docutils_.py @@ -278,7 +278,7 @@ def parse(self, inputstring: str, document: nodes.document) -> None: for i, line in enumerate(inputstring.split("\n")): if len(line) > document.settings.line_length_limit: error = document.reporter.error( - f"Line {i+1} exceeds the line-length-limit:" + f"Line {i + 1} exceeds the line-length-limit:" f" {document.settings.line_length_limit}." ) document.append(error) @@ -479,7 +479,7 @@ def visit_rubric_html(self, node): So here we override the visit/depart methods to output the correct element """ if "level" in node: - self.body.append(self.starttag(node, f'h{node["level"]}', "", CLASS="rubric")) + self.body.append(self.starttag(node, f"h{node['level']}", "", CLASS="rubric")) else: self.body.append(self.starttag(node, "p", "", CLASS="rubric")) @@ -490,7 +490,7 @@ def depart_rubric_html(self, node): See explanation in `visit_rubric_html` """ if "level" in node: - self.body.append(f'\n') + self.body.append(f"\n") else: self.body.append("

\n")