Skip to content

Commit 67be2c5

Browse files
sciyoshiCopilot
andauthored
Update Ruff, support Python 3.13 and use pyright for typechecking (#320)
* Ruff update * types improvements * typing from_dom * Switch to pyright * Add python 3.13 * try linting on 3.13 * fix lint * use uv for release * Update prosemirror/model/from_dom.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * remove mypy section --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7f16822 commit 67be2c5

File tree

9 files changed

+177
-162
lines changed

9 files changed

+177
-162
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ jobs:
1515
- uses: actions/checkout@v4
1616
- uses: actions/setup-python@v5
1717
with:
18-
python-version: "3.12"
18+
python-version: "3.13"
1919
- run: pip install uv
20-
- run: uv venv
21-
- run: uv pip install --requirement pyproject.toml
22-
- run: uv pip install setuptools setuptools-scm wheel build
23-
- run: .venv/bin/python -m build --no-isolation
24-
- name: Publish package distributions to PyPI
25-
uses: pypa/gh-action-pypi-publish@release/v1
20+
- run: uv build
21+
- run: uv publish

.github/workflows/test.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ["3.10", "3.11", "3.12"]
14+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1515
steps:
1616
- uses: actions/checkout@v4
1717
- uses: actions/setup-python@v5
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020
- run: pip install uv
2121
- run: uv venv
22-
- run: uv pip install --requirement pyproject.toml --all-extras
23-
- run: .venv/bin/pytest --cov=./prosemirror/
24-
- run: .venv/bin/codecov
22+
- run: uv sync
23+
- run: uv run pytest --cov=./prosemirror/
24+
- run: uv run codecov
2525
if: matrix.python-version == '3.11'
2626
env:
2727
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
@@ -31,9 +31,11 @@ jobs:
3131
steps:
3232
- uses: actions/checkout@v4
3333
- uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.13"
3436
- run: pip install uv
3537
- run: uv venv
36-
- run: uv pip install --requirement pyproject.toml --all-extras
37-
- run: .venv/bin/ruff format --check prosemirror tests
38-
- run: .venv/bin/ruff check prosemirror tests
39-
- run: .venv/bin/mypy prosemirror
38+
- run: uv sync
39+
- run: uv run ruff format --check prosemirror tests
40+
- run: uv run ruff check prosemirror tests
41+
- run: uv run pyright prosemirror

prosemirror/model/content.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from dataclasses import dataclass
23
from functools import cmp_to_key, reduce
34
from typing import (
45
TYPE_CHECKING,
@@ -18,23 +19,17 @@
1819
from .schema import NodeType
1920

2021

22+
@dataclass
2123
class MatchEdge:
2224
type: "NodeType"
2325
next: "ContentMatch"
2426

25-
def __init__(self, type: "NodeType", next: "ContentMatch") -> None:
26-
self.type = type
27-
self.next = next
28-
2927

28+
@dataclass
3029
class WrapCacheEntry:
3130
target: "NodeType"
3231
computed: list["NodeType"] | None
3332

34-
def __init__(self, target: "NodeType", computed: list["NodeType"] | None) -> None:
35-
self.target = target
36-
self.computed = computed
37-
3833

3934
class Active(TypedDict):
4035
match: "ContentMatch"
@@ -118,7 +113,7 @@ def fill_before(
118113
to_end: bool = False,
119114
start_index: int = 0,
120115
) -> Fragment | None:
121-
seen = [self]
116+
seen: list[ContentMatch] = [self]
122117

123118
def search(match: ContentMatch, types: list["NodeType"]) -> Fragment | None:
124119
nonlocal seen
@@ -289,7 +284,7 @@ class NameExpr(TypedDict):
289284

290285

291286
def parse_expr(stream: TokenStream) -> Expr:
292-
exprs = []
287+
exprs: list[Expr] = []
293288
while True:
294289
exprs.append(parse_expr_seq(stream))
295290
if not stream.eat("|"):
@@ -300,7 +295,7 @@ def parse_expr(stream: TokenStream) -> Expr:
300295

301296

302297
def parse_expr_seq(stream: TokenStream) -> Expr:
303-
exprs = []
298+
exprs: list[Expr] = []
304299
while True:
305300
exprs.append(parse_expr_subscript(stream))
306301
next_ = stream.next()
@@ -312,7 +307,7 @@ def parse_expr_seq(stream: TokenStream) -> Expr:
312307

313308

314309
def parse_expr_subscript(stream: TokenStream) -> Expr:
315-
expr = parse_expr_atom(stream)
310+
expr: Expr = parse_expr_atom(stream)
316311
while True:
317312
if stream.eat("+"):
318313
expr = {"type": "plus", "expr": expr}

prosemirror/model/fragment.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
cast,
99
)
1010

11-
from prosemirror.utils import JSON, JSONList, text_length
11+
from prosemirror.utils import JSON, JSONDict, JSONList, text_length
1212

1313
if TYPE_CHECKING:
1414
from prosemirror.model.schema import Schema
@@ -89,8 +89,8 @@ def iteratee(
8989
elif node.is_leaf:
9090
if leaf_text:
9191
text.append(leaf_text(node) if callable(leaf_text) else leaf_text)
92-
elif node.type.spec.get("leafText") is not None:
93-
text.append(node.type.spec["leafText"](node))
92+
elif (node_leaf_text := node.type.spec.get("leafText")) is not None:
93+
text.append(node_leaf_text(node))
9494
separated = not block_separator
9595
elif not separated and node.is_block:
9696
text.append(block_separator)
@@ -267,7 +267,7 @@ def from_json(cls, schema: "Schema[Any, Any]", value: JSON) -> "Fragment":
267267
msg = "Invalid input for Fragment.from_json"
268268
raise ValueError(msg)
269269

270-
return cls([schema.node_from_json(item) for item in value])
270+
return cls([schema.node_from_json(cast(JSONDict, item)) for item in value])
271271

272272
@classmethod
273273
def from_array(cls, array: list["Node"]) -> "Fragment":

0 commit comments

Comments
 (0)