Skip to content

Commit

Permalink
Fix some type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Jan 13, 2025
1 parent 45824d2 commit f54c1b0
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions rewrite/rewrite/python/format/normalize_line_breaks_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
J2 = TypeVar('J2', bound=J)


class NormalizeLineBreaksVisitor(PythonVisitor):
class NormalizeLineBreaksVisitor(PythonVisitor[P]):
def __init__(self, style: GeneralFormatStyle, stop_after: Optional[Tree] = None):
self._stop_after = stop_after
self._stop = False
Expand All @@ -19,7 +19,7 @@ def __init__(self, style: GeneralFormatStyle, stop_after: Optional[Tree] = None)
def visit_space(self, space: Optional[Space], loc: Optional[Union[PySpace.Location, Space.Location]],
p: P) -> Space:
if not space or space is Space.EMPTY or not space.whitespace:
return space
return space # type: ignore
s = space.with_whitespace(_normalize_new_lines(space.whitespace, self._style.use_crlf_new_lines))

def process_comment(comment: Comment) -> Comment:
Expand All @@ -40,20 +40,17 @@ def post_visit(self, tree: T, _: object) -> Optional[T]:
self._stop = True
return tree

def visit(self, tree: Optional[Tree], p: P, parent: Optional[Cursor] = None) -> Optional[T]:
return tree if self._stop else super().visit(tree, p, parent)
def visit(self, tree: Optional[Tree], p: P, parent: Optional[Cursor] = None) -> Optional[J]:
return cast(J, tree) if self._stop else super().visit(tree, p, parent)

def visit_marker(self, marker: Marker, p: P) -> Marker:
m = cast(Marker, super().visit_marker(marker, p))
m = super().visit_marker(marker, p)
if isinstance(m, TrailingComma):
return m.with_suffix(self.visit_space(m.suffix, None, p))
return m


STR = TypeVar('STR', bound=Optional[str])


def _normalize_new_lines(text: STR, use_crlf: bool) -> STR:
def _normalize_new_lines(text: str, use_crlf: bool) -> str:
"""
Normalize the line breaks in the given text to either use of CRLF or LF.
Expand Down

0 comments on commit f54c1b0

Please sign in to comment.