How to use the flynt.lexer.Chunk.Chunk function in flynt

To help you get started, we’ve selected a few flynt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ikamensh / flynt / src / flynt / lexer / split.py View on Github external
try:
        for item in g:
            t = PyToken(item)
            reuse = chunk.append(t)

            if chunk.complete:

                yield chunk
                chunk = Chunk()
                if reuse:
                    reuse = chunk.append(t)
                    # assert not reuse
                    if chunk.complete:
                        yield chunk
                        chunk = Chunk()

        yield chunk
    except tokenize.TokenError as e:
        if state.verbose:
            traceback.print_exc()
            print(e)
github ikamensh / flynt / src / flynt / lexer / split.py View on Github external
def get_chunks(code) -> Generator[Chunk, None, None]:
    g = tokenize.tokenize(io.BytesIO(code.encode("utf-8")).readline)
    chunk = Chunk()

    try:
        for item in g:
            t = PyToken(item)
            reuse = chunk.append(t)

            if chunk.complete:

                yield chunk
                chunk = Chunk()
                if reuse:
                    reuse = chunk.append(t)
                    # assert not reuse
                    if chunk.complete:
                        yield chunk
                        chunk = Chunk()
github ikamensh / flynt / src / flynt / lexer / split.py View on Github external
def get_fstringify_chunks(code: str) -> Generator[Chunk, None, None]:
    """
    A generator yielding Chunks of the code where fstring can be formed.
    """
    last_concat = False

    for chunk in get_chunks(code):
        if chunk.successful and not last_concat:
            yield chunk

        if len(chunk) and chunk[-1].is_string():
            last_concat = True
        else:
            if Chunk.multiline or len(chunk) > 0:
                last_concat = False
github ikamensh / flynt / src / flynt / lexer / __init__.py View on Github external
from flynt.lexer.Chunk import Chunk as _Chunk

set_multiline = _Chunk.set_multiline
set_single_line = _Chunk.set_single_line
set_multiline()
github ikamensh / flynt / src / flynt / lexer / __init__.py View on Github external
from flynt.lexer.Chunk import Chunk as _Chunk

set_multiline = _Chunk.set_multiline
set_single_line = _Chunk.set_single_line
set_multiline()