Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
rev: v0.16.0
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v2.1.0
rev: v2.3.0
hooks:
- id: mypy
args: [--config-file=pyproject.toml]
Expand Down
6 changes: 3 additions & 3 deletions myst_parser/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ def run(self):
### MyST Lexer ###
# TODO when some more work and testing, this should be made available publicly

from pygments import token # noqa: E402
from pygments.lexer import bygroups, inherit, this, using # noqa: E402
from pygments.lexers.markup import MarkdownLexer # noqa: E402
from pygments import token
from pygments.lexer import bygroups, inherit, this, using
from pygments.lexers.markup import MarkdownLexer


class MystLexer(MarkdownLexer):
Expand Down
4 changes: 2 additions & 2 deletions myst_parser/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def filter_string(


def fetch_inventory(
uri: str, *, timeout: None | float = None, base_url: None | str = None
uri: str, *, timeout: float | None = None, base_url: str | None = None
) -> InventoryType:
"""Fetch an inventory from a URL or local path."""
if uri.startswith(("http://", "https://")):
Expand All @@ -421,7 +421,7 @@ def fetch_inventory(
return load(stream, base_url=base_url)


def inventory_cli(inputs: None | list[str] = None):
def inventory_cli(inputs: list[str] | None = None):
"""Command line interface for fetching and parsing an inventory."""
parser = argparse.ArgumentParser(description="Parse an inventory file.")
parser.add_argument("uri", metavar="[URL|PATH]", help="URI of the inventory file")
Expand Down
8 changes: 4 additions & 4 deletions myst_parser/mdit_to_docutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, parser: MarkdownIt) -> None:
if k.startswith("render_") and k != "render_children"
}
# these are lazy loaded, when needed
self._inventories: None | dict[str, inventory.InventoryType] = None
self._inventories: dict[str, inventory.InventoryType] | None = None

def __getattr__(self, name: str):
"""Warn when the renderer has not been setup yet."""
Expand Down Expand Up @@ -300,7 +300,7 @@ def nested_render_text(
text: str,
lineno: int,
inline: bool = False,
temp_root_node: None | nodes.Element = None,
temp_root_node: nodes.Element | None = None,
heading_offset: int = 0,
) -> None:
"""Render unparsed text (appending to the current node).
Expand Down Expand Up @@ -988,7 +988,7 @@ def render_link(self, token: SyntaxTreeNode) -> None:
return self.render_link_unknown(token)

def render_link_url(
self, token: SyntaxTreeNode, conversion: None | UrlSchemeType = None
self, token: SyntaxTreeNode, conversion: UrlSchemeType | None = None
) -> None:
"""Render link token (including autolink and linkify),
where the link has been identified as an external URL.
Expand Down Expand Up @@ -2113,7 +2113,7 @@ def default_slugify(title: str) -> str:
def compute_unique_slug(
token_tree: SyntaxTreeNode,
slugs: Container[str],
slug_func: None | Callable[[str], str] = None,
slug_func: Callable[[str], str] | None = None,
) -> str:
"""Compute the slug for a heading token, unique against existing slugs."""
slug_func = github_slugify if slug_func is None else slug_func
Expand Down
2 changes: 1 addition & 1 deletion myst_parser/mdit_to_docutils/sphinx_.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def render_link_unknown(self, token: SyntaxTreeNode) -> None:
path_dest, *_path_ids = destination.split("#", maxsplit=1)
path_id = _path_ids[0] if _path_ids else None

potential_path: None | Path = None
potential_path: Path | None = None
if self.sphinx_env.srcdir: # not set in some test situations
_, path_str = self.sphinx_env.relfn2path(path_dest, self.sphinx_env.docname)
potential_path = Path(path_str)
Expand Down
2 changes: 1 addition & 1 deletion myst_parser/mdit_to_docutils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def apply(self, **kwargs: t.Any) -> None:

# gather explicit references
# this follows the same logic as Sphinx's StandardDomain.process_doc
explicit: dict[str, tuple[str, None | str]] = {}
explicit: dict[str, tuple[str, str | None]] = {}
for name, is_explicit in self.document.nametypes.items():
if not is_explicit:
continue
Expand Down
2 changes: 1 addition & 1 deletion myst_parser/parsers/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _parse_directive_options(
:param additional_options: Additional options for the directive,
which the options block takes priority over
"""
options_block: None | str = None
options_block: str | None = None
options_position: int | None = None
"""The 1-based source line of the first line of the options block."""
if content.startswith("---"):
Expand Down
2 changes: 1 addition & 1 deletion myst_parser/parsers/docutils_.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def parse(self, inputstring: str, document: nodes.document) -> None:
pass # this will be reported during the render
else:
if topmatter:
warning = lambda wtype, msg: create_warning( # noqa: E731
warning = lambda wtype, msg: create_warning(
document, msg, wtype, line=1, append_to=document
)
config = merge_file_level(config, topmatter, warning)
Expand Down
6 changes: 2 additions & 4 deletions myst_parser/parsers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,7 @@ def _scan_block_scalar(

# Determine the indentation level and go to the first non-empty line.
min_indent = indent + 1
if min_indent < 1:
min_indent = 1
min_indent = max(min_indent, 1)
if increment is None:
breaks, max_indent, end_mark = _scan_block_scalar_indentation(stream)
indent = max(min_indent, max_indent)
Expand Down Expand Up @@ -652,8 +651,7 @@ def _scan_block_scalar_indentation(
end_mark = stream.get_position()
else:
stream.forward()
if stream.column > max_indent:
max_indent = stream.column
max_indent = max(max_indent, stream.column)
return chunks, max_indent, end_mark


Expand Down
3 changes: 1 addition & 2 deletions myst_parser/parsers/parse_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from collections import abc, deque
from collections.abc import Callable, Iterable, Iterator
from html.parser import HTMLParser
from typing import Any


class Attribute(dict):
Expand Down Expand Up @@ -138,7 +137,7 @@ def render(
def __str__(self) -> str:
return self.render()

def __eq__(self, item: Any) -> bool:
def __eq__(self, item: object) -> bool:
return item is self

def walk(self, include_self: bool = False) -> Iterator[Element]:
Expand Down
2 changes: 1 addition & 1 deletion myst_parser/parsers/sphinx_.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def parse(self, inputstring: str, document: nodes.document) -> None:
pass # this will be reported during the render
else:
if topmatter:
warning = lambda wtype, msg: create_warning( # noqa: E731
warning = lambda wtype, msg: create_warning(
document, msg, wtype, line=1, append_to=document
)
config = merge_file_level(config, topmatter, warning)
Expand Down
8 changes: 4 additions & 4 deletions myst_parser/sphinx_ext/myst_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MystReferenceResolver(ReferencesResolver):
default_priority = 9 # higher priority than ReferencesResolver (10)

def log_warning(
self, target: None | str, msg: str, subtype: MystWarnings, **kwargs: Any
self, target: str | None, msg: str, subtype: MystWarnings, **kwargs: Any
):
"""Log a warning, with a myst type and specific subtype."""

Expand Down Expand Up @@ -80,7 +80,7 @@ def run(self, **kwargs: Any) -> None:
contnode = cast(nodes.TextElement, node[0].deepcopy())
target = node["reftarget"]
refdoc = node.get("refdoc", self.env.docname)
search_domains: None | list[str] = self.env.config.myst_ref_domains
search_domains: list[str] | None = self.env.config.myst_ref_domains

# try to resolve the reference within the local project,
# this asks all domains to resolve the reference,
Expand Down Expand Up @@ -233,7 +233,7 @@ def resolve_myst_ref_any(
refdoc: str,
node: pending_xref,
contnode: Element,
only_domains: None | list[str],
only_domains: list[str] | None,
) -> Element | None:
"""Resolve reference generated by the "myst" role; ``[text](#reference)``.

Expand Down Expand Up @@ -393,7 +393,7 @@ def _resolve_myst_ref_intersphinx(
contnode: nodes.Element,
target: str,
only_domains: list[str] | None,
) -> None | nodes.reference:
) -> nodes.reference | None:
"""Resolve a myst reference to an intersphinx inventory."""
matches = [
m
Expand Down
Loading