Skip to content

Find smallest number of *non-symmetric* extra context lines around each modified block #241

Open
@akaihola

Description

@akaihola

Currently, Darker checks whether the AST of a .py file stays intact after applying Black changes to modified lines only. If the AST check fails, Darker will find the smallest number of extra context lines to add before (let's call that B) and after (A) each contiguous set of modified lines such that AST verification will pass.

The number of extra context lines is currently symmetric, i.e. even if e.g. skipping reformatting for the line immediately following a modified block wouldn't change the AST, it will still be reformatted if at least one line preceding the block must be reformatted to preserve the AST. In other words, A == B holds always.

What we could do after finding the smallest possible A (== B) is to keep B fixed and continue bisecting just A to find the smallest possible extra number of lines before the modified block. After that, we could do the same for B while keeping A fixed to the new value. This way we would find the smallest non-symmetric block around a modified section of the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions