Skip to content

Proposal for optimization (requires refactoring) #90

@MischaPanch

Description

@MischaPanch

Currently all lines are taken into account in the from_lines method, and then are used for every check in a loop afterwards. This is inefficient - lines that are unused for matching (like comments and empty lines) should rather be filtered out once during initialization instead of looping over them in each check.

This could be done in a clean way by adding a method accepts_line to the Pattern (or rather a PatternFactory, see below) class, implement it in the implementations, and use it for filtering at construction of PathSpec.

Unfortunately, with the current functional-ish design this is not possible. from_lines accepts Callable[[AnyStr], Pattern] as pattern_factory instead of a PatternFactory class, and we can't assume anything about this callable (like an additional method for checking line appropriateness).

One could solve this by actually introducing a PatternFactory class and use that one instead of Callable for annotations, but it would break backwards compatibility. I think generally relying on Callables instead of factory classes has multiple downsides in the codebase - the existing and allowed pattern factories are not easily discoverable (as they would be through type hierarchy and name conventions). And, of course, there are the extendibility problems like the inability to add a filtering method I mentioned,

This is just a proposal, I understand if you want to keep the mix of the object-oriented and functional approach in your codebase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions