Skip to content

Commit

Permalink
Merge pull request #310 from fellowapp/dependabot/pip/ruff-0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Apr 16, 2024
2 parents a7cb175 + 0f3cbe5 commit d3dd91e
Show file tree
Hide file tree
Showing 22 changed files with 378 additions and 505 deletions.
240 changes: 89 additions & 151 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions prosemirror/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

__all__ = [
"Fragment",
"Mapping",
"Mark",
"Node",
"ResolvedPos",
"Schema",
"Slice",
"basic_schema",
"Mapping",
"Step",
"Transform",
"basic_schema",
]
18 changes: 9 additions & 9 deletions prosemirror/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
from .to_dom import DOMSerializer

__all__ = [
"ContentMatch",
"DOMParser",
"DOMSerializer",
"Fragment",
"Mark",
"MarkType",
"Node",
"ResolvedPos",
"NodeRange",
"Fragment",
"Slice",
"NodeType",
"ReplaceError",
"Mark",
"ResolvedPos",
"Schema",
"NodeType",
"MarkType",
"ContentMatch",
"DOMSerializer",
"DOMParser",
"Slice",
]
18 changes: 8 additions & 10 deletions prosemirror/model/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def search(match: ContentMatch, types: List["NodeType"]) -> Optional[Fragment]:
nonlocal seen
finished = match.match_fragment(after, start_index)
if finished and (not to_end or finished.valid_end):
return Fragment.from_(
[cast("Node", tp.create_and_fill()) for tp in types]
)
return Fragment.from_([
cast("Node", tp.create_and_fill()) for tp in types
])
for i in match.next:
type = i.type
next = i.next
Expand Down Expand Up @@ -167,13 +167,11 @@ def compute_wrapping(self, target: "NodeType") -> Optional[List["NodeType"]]:
and type.name not in seen
and (not current["type"] or match.next[i].next.valid_end)
):
active.append(
{
"match": type.content_match,
"via": current,
"type": type,
}
)
active.append({
"match": type.content_match,
"via": current,
"type": type,
})
seen[type.name] = True
return None

Expand Down
31 changes: 15 additions & 16 deletions prosemirror/model/from_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ def __init__(self, schema: Schema[Any, Any], rules: List[ParseRule]) -> None:

self._styles = [rule for rule in rules if rule.style is not None]

self.normalize_lists = not any(
[
schema.nodes[r.node].content_match.match_type(schema.nodes[r.node])
for r in self._tags
if r.node is not None
and r.tag is not None
and re.match(r"^(ul|ol)\b", r.tag) is not None
]
)
self.normalize_lists = not any([
schema.nodes[r.node].content_match.match_type(schema.nodes[r.node])
for r in self._tags
if r.node is not None
and r.tag is not None
and re.match(r"^(ul|ol)\b", r.tag) is not None
])

def parse(
self, dom_: lxml.html.HtmlElement, options: Optional[ParseOptions] = None
Expand Down Expand Up @@ -189,10 +187,11 @@ def match_style(
if (
style is None
or style.index(prop) != 0
or rule.context
and not context.matches_context(rule.context)
or len(style) > len(prop)
and (ord(style[len(prop)]) != 61 or style[len(prop) + 1 :] != value)
or (rule.context and not context.matches_context(rule.context))
or (
len(style) > len(prop)
and (ord(style[len(prop)]) != 61 or style[len(prop) + 1 :] != value)
)
):
continue

Expand Down Expand Up @@ -929,9 +928,9 @@ def find_in_text(self, text_node: DOMNode) -> None:

def matches_context(self, context: str) -> bool:
if "|" in context:
return any(
[self.matches_context(s) for s in re.split(r"\s*\|\s*", context)]
)
return any([
self.matches_context(s) for s in re.split(r"\s*\|\s*", context)
])

parts = context.split("/")
option = self.options.context
Expand Down
10 changes: 4 additions & 6 deletions prosemirror/model/resolvedpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ def min(self, other: "ResolvedPos") -> "ResolvedPos":
return other if other.pos < self.pos else self

def __str__(self) -> str:
path = "/".join(
[
f"{self.node(i).type.name}_{self.index(i - 1)}"
for i in range(1, self.depth + 1)
]
)
path = "/".join([
f"{self.node(i).type.name}_{self.index(i - 1)}"
for i in range(1, self.depth + 1)
])
return f"{path}:{self.parent_offset}"

@classmethod
Expand Down
38 changes: 18 additions & 20 deletions prosemirror/model/to_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,23 @@ def __str__(self) -> str:
return "".join([str(c) for c in self.children])


SELF_CLOSING_ELEMENTS = frozenset(
{
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"keygen",
"link",
"meta",
"param",
"source",
"track",
"wbr",
}
)
SELF_CLOSING_ELEMENTS = frozenset({
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"keygen",
"link",
"meta",
"param",
"source",
"track",
"wbr",
})


class Element(DocumentFragment):
Expand Down Expand Up @@ -208,7 +206,7 @@ def marks_from_schema(


def gather_to_dom(
obj: Mapping[str, Union[NodeType, MarkType]]
obj: Mapping[str, Union[NodeType, MarkType]],
) -> Dict[str, Callable[..., Any]]:
result = {}
for name in obj:
Expand Down
20 changes: 9 additions & 11 deletions prosemirror/schema/list/schema_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ def add_list_nodes(
nodes: Dict["Nodes", "NodeSpec"], item_content: str, list_group: str
) -> Dict["Nodes", "NodeSpec"]:
copy = nodes.copy()
copy.update(
{
cast(Nodes, "ordered_list"): add(
orderd_list, NodeSpec(content="list_item+", group=list_group)
),
cast(Nodes, "bullet_list"): add(
bullet_list, NodeSpec(content="list_item+", group=list_group)
),
cast(Nodes, "list_item"): add(list_item, NodeSpec(content=item_content)),
}
)
copy.update({
cast(Nodes, "ordered_list"): add(
orderd_list, NodeSpec(content="list_item+", group=list_group)
),
cast(Nodes, "bullet_list"): add(
bullet_list, NodeSpec(content="list_item+", group=list_group)
),
cast(Nodes, "list_item"): add(list_item, NodeSpec(content=item_content)),
})
return copy
22 changes: 9 additions & 13 deletions prosemirror/test_builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@

nodes = add_list_nodes(_schema.spec["nodes"], "paragraph block*", "block")

nodes.update(
{
"doc": {
"content": "block+",
"attrs": {"meta": {"default": None}},
}
nodes.update({
"doc": {
"content": "block+",
"attrs": {"meta": {"default": None}},
}
)
})

test_schema: Schema[Any, Any] = Schema(
{
"nodes": nodes,
"marks": _schema.spec["marks"],
}
)
test_schema: Schema[Any, Any] = Schema({
"nodes": nodes,
"marks": _schema.spec["marks"],
})

out = builders(
test_schema,
Expand Down
34 changes: 17 additions & 17 deletions prosemirror/transform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@
from .transform import Transform, TransformError

__all__ = [
"Transform",
"TransformError",
"AddMarkStep",
"AddNodeMarkStep",
"AttrStep",
"MapResult",
"Mapping",
"RemoveMarkStep",
"RemoveNodeMarkStep",
"ReplaceAroundStep",
"ReplaceStep",
"Step",
"StepMap",
"StepResult",
"join_point",
"Transform",
"TransformError",
"can_join",
"can_split",
"insert_point",
"drop_point",
"lift_target",
"find_wrapping",
"close_fragment",
"covered_depths",
"drop_point",
"find_wrapping",
"fits_trivially",
"insert_point",
"join_point",
"lift_target",
"replace_step",
"StepMap",
"MapResult",
"Mapping",
"AttrStep",
"AddMarkStep",
"AddNodeMarkStep",
"RemoveMarkStep",
"ReplaceAroundStep",
"RemoveNodeMarkStep",
"ReplaceStep",
"replace_step",
]
18 changes: 6 additions & 12 deletions prosemirror/transform/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ def deleted_across(self) -> bool:

class Mappable(metaclass=abc.ABCMeta):
@abc.abstractmethod
def map(self, pos: int, assoc: int = 1) -> int:
...
def map(self, pos: int, assoc: int = 1) -> int: ...

@abc.abstractmethod
def map_result(self, pos: int, assoc: int = 1) -> MapResult:
...
def map_result(self, pos: int, assoc: int = 1) -> MapResult: ...


class StepMap(Mappable):
Expand Down Expand Up @@ -92,12 +90,10 @@ def map_result(self, pos: int, assoc: int = 1) -> MapResult:
return self._map(pos, assoc, False)

@overload
def _map(self, pos: int, assoc: int, simple: Literal[True]) -> int:
...
def _map(self, pos: int, assoc: int, simple: Literal[True]) -> int: ...

@overload
def _map(self, pos: int, assoc: int, simple: Literal[False]) -> MapResult:
...
def _map(self, pos: int, assoc: int, simple: Literal[False]) -> MapResult: ...

def _map(self, pos: int, assoc: int, simple: bool) -> Union[MapResult, int]:
diff = 0
Expand Down Expand Up @@ -257,12 +253,10 @@ def map_result(self, pos: int, assoc: int = 1) -> MapResult:
return self._map(pos, assoc, False)

@overload
def _map(self, pos: int, assoc: int, simple: Literal[True]) -> int:
...
def _map(self, pos: int, assoc: int, simple: Literal[True]) -> int: ...

@overload
def _map(self, pos: int, assoc: int, simple: Literal[False]) -> MapResult:
...
def _map(self, pos: int, assoc: int, simple: Literal[False]) -> MapResult: ...

def _map(self, pos: int, assoc: int, simple: bool) -> Union[MapResult, int]:
del_info = 0
Expand Down
2 changes: 1 addition & 1 deletion prosemirror/transform/mark_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def invert(self, doc: Optional[Node] = None) -> Step:
def map(self, mapping: Mappable) -> Optional[Step]:
from_ = mapping.map_result(self.from_, 1)
to = mapping.map_result(self.to, -1)
if from_.deleted and to.deleted or from_.pos > to.pos:
if (from_.deleted and to.deleted) or from_.pos > to.pos:
return None
return AddMarkStep(from_.pos, to.pos, self.mark)

Expand Down
6 changes: 3 additions & 3 deletions prosemirror/transform/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def fits_trivially(


class _FrontierItem:
__slots__ = ("type", "match")
__slots__ = ("match", "type")

def __init__(self, type_: NodeType, match: ContentMatch) -> None:
self.type = type_
self.match = match


class _Fittable:
__slots__ = ("slice_depth", "frontier_depth", "parent", "inject", "wrap")
__slots__ = ("frontier_depth", "inject", "parent", "slice_depth", "wrap")

def __init__(
self,
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(


class Fitter:
__slots__ = ("to_", "from__", "unplaced", "frontier", "placed")
__slots__ = ("from__", "frontier", "placed", "to_", "unplaced")

def __init__(self, from__: ResolvedPos, to_: ResolvedPos, slice: Slice) -> None:
self.to_ = to_
Expand Down
Loading

0 comments on commit d3dd91e

Please sign in to comment.