Skip to content

Commit b84e7f5

Browse files
sciyoshiclaude
andcommitted
fix: resolve ty call-top-callable errors on union types
Use isinstance narrowing and cast to avoid callable() checks on union types containing Mapping, which ty considers potentially callable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bc71466 commit b84e7f5

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

prosemirror/model/fragment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ def iteratee(
9292
].decode("utf-16-le")
9393
elif node.is_leaf:
9494
if leaf_text:
95-
node_text = leaf_text(node) if callable(leaf_text) else leaf_text
95+
node_text = (
96+
leaf_text if isinstance(leaf_text, str) else leaf_text(node)
97+
)
9698
elif (node_leaf_text := node.type.spec.get("leafText")) is not None:
9799
node_text = node_leaf_text(node)
98100
else:

prosemirror/model/from_dom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,10 @@ def add_element_by_rule(
811811

812812
if isinstance(rule.content_element, str):
813813
content_dom = dom_.cssselect(rule.content_element)[0]
814-
elif callable(rule.content_element):
815-
content_dom = rule.content_element(dom_)
816-
elif rule.content_element is not None:
814+
elif isinstance(rule.content_element, DOMNode):
817815
content_dom = rule.content_element
816+
elif rule.content_element is not None:
817+
content_dom = rule.content_element(dom_)
818818

819819
self.find_around(dom_, content_dom, True)
820820
self.add_all(content_dom, marks)

prosemirror/transform/transform.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from collections.abc import Callable
3-
from typing import Optional, TypedDict
3+
from typing import Optional, TypedDict, cast
44

55
from prosemirror.model import (
66
ContentMatch,
@@ -552,13 +552,18 @@ def set_block_type(
552552
raise ValueError(msg)
553553
map_from = len(self.steps)
554554

555+
get_attrs = cast(
556+
"Callable[[Node], Attrs] | None", attrs if callable(attrs) else None
557+
)
558+
static_attrs = cast("Attrs | None", None if callable(attrs) else attrs)
559+
555560
def iteratee(
556561
node: "Node",
557562
pos: int,
558563
parent: Optional["Node"],
559564
i: int,
560565
) -> bool | None:
561-
attrs_here = attrs(node) if callable(attrs) else attrs
566+
attrs_here = get_attrs(node) if get_attrs else static_attrs
562567
if (
563568
node.is_textblock
564569
and not node.has_markup(type, attrs_here)

0 commit comments

Comments
 (0)