Skip to content

Allow application-defined auditing of normalized gitignore segments - #153

Open
sricharanreddycheruku wants to merge 1 commit into
cpburnz:masterfrom
sricharanreddycheruku:add-gitignore-segment-audit
Open

sricharanreddycheruku wants to merge 1 commit into
cpburnz:masterfrom
sricharanreddycheruku:add-gitignore-segment-audit

Conversation

@sricharanreddycheruku

Copy link
Copy Markdown

Related to #131: implements the maintainer's suggested optional segment-auditing
hook without imposing hard-coded limits on normal patterns.

Add an overridable _audit_segments() class method to both gitignore pattern
classes. Existing PathSpec/GitIgnoreSpec pattern_factory arguments let applications
supply an audited subclass. The hook receives an immutable tuple after normalization
and before regex translation, including optimized regex-override patterns. Comments,
null patterns and precompiled expressions are not audited. Rejection exceptions
propagate unchanged regardless of the pattern-notation errors policy.

Document a subclass example and the hook's limitations: a wildcard-count policy is
application-defined and does not guarantee bounded matching time. Update API docs,
change history and strict typed-usage examples.

Validation:

  • New auditing tests: 6 methods with 66 passing subtests. The same tests on the
    original source report 53 failures (including subtests), with 19 passing controls.
  • Complete Python 3.12.14 and 3.14.7 suites with simple, RE2 and Hyperscan installed:
    238 passed, 1 skipped, 974 subtests passed on each.
  • Python 3.9.25, the minimum supported version: 178 passed, 61 optional-backend skips.
  • The project's unittest-discover command passes all 239 tests, with 1 skipped.
  • Warning-as-error Sphinx HTML build passes.
  • mypy and pyright pass for Python 3.14 targets, including the audited subclasses.
    Targeting Python 3.12 reports existing _typing.py fallback errors; the same mypy
    errors are reproduced on unchanged upstream source.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant