Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove legacy tokenizer/lexer candidates generator #184

Merged
merged 4 commits into from
Jun 17, 2023
Merged
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
68 changes: 0 additions & 68 deletions src/flynt/candidates/PyToken.py

This file was deleted.

171 changes: 0 additions & 171 deletions src/flynt/candidates/chunk.py

This file was deleted.

23 changes: 0 additions & 23 deletions src/flynt/candidates/context.py

This file was deleted.

62 changes: 0 additions & 62 deletions src/flynt/candidates/split.py

This file was deleted.

24 changes: 12 additions & 12 deletions src/flynt/code_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import string
import sys
from functools import lru_cache, partial
from typing import Callable, List, Optional, Tuple, Union
from typing import Callable, List, Optional, Tuple

from flynt.candidates.ast_call_candidates import call_candidates
from flynt.candidates.ast_chunk import AstChunk
from flynt.candidates.ast_percent_candidates import percent_candidates
from flynt.candidates.chunk import Chunk
from flynt.exceptions import FlyntException
from flynt.format import QuoteTypes as qt
from flynt.format import get_quote_type
Expand Down Expand Up @@ -94,12 +93,12 @@ def code_between(
return "\n".join(result)

@lru_cache(None)
def code_in_chunk(self, chunk: Union[Chunk, AstChunk]):
def code_in_chunk(self, chunk: AstChunk):
return self.code_between(
chunk.start_line, chunk.start_idx, chunk.end_line, chunk.end_idx
)

def fill_up_to(self, chunk: Union[Chunk, AstChunk]) -> None:
def fill_up_to(self, chunk: AstChunk) -> None:
start_line, start_idx, _ = (chunk.start_line, chunk.start_idx, chunk.end_idx)
if start_line == self.last_line:
self.results.append(
Expand All @@ -120,7 +119,7 @@ def fill_up_to_line(self, line: int) -> None:
self.results.append(self.src_lines[self.last_line] + "\n")
self.last_line += 1

def try_chunk(self, chunk: Union[Chunk, AstChunk]) -> None:
def try_chunk(self, chunk: AstChunk) -> None:
"""Try applying a transform to a chunk of code.

Transformation function is free to decide to refuse conversion,
Expand Down Expand Up @@ -161,7 +160,7 @@ def try_chunk(self, chunk: Union[Chunk, AstChunk]) -> None:

def maybe_replace(
self,
chunk: Union[Chunk, AstChunk],
chunk: AstChunk,
contract_lines: int,
converted: str,
rest: str,
Expand Down Expand Up @@ -231,17 +230,18 @@ def add_rest(self) -> None:
self.last_line += 1


def fstring_candidates(code, state):
chunks = percent_candidates(code, state) + call_candidates(code, state)
chunks.sort(key=lambda c: (c.start_line, c.start_idx))
return chunks


def fstringify_code_by_line(code: str, state: State) -> Tuple[str, int]:
"""returns fstringified version of the code and amount of lines edited."""

def candidates(code, state):
chunks = percent_candidates(code, state) + call_candidates(code, state)
chunks.sort(key=lambda c: (c.start_line, c.start_idx))
return chunks

return _transform_code(
code,
partial(candidates, state=state),
partial(fstring_candidates, state=state),
partial(transform_chunk, state=state),
state,
)
Expand Down
Loading