Skip to content

Fix pattern-limit accounting with exclusions - #243

Merged
facelessuser merged 1 commit into
facelessuser:mainfrom
Rexyysilent:codex/pattern-limit-accounting
Oct 17, 2026
Merged

facelessuser merged 1 commit into
facelessuser:mainfrom
Rexyysilent:codex/pattern-limit-accounting

Conversation

@Rexyysilent

Copy link
Copy Markdown
Contributor

Exclusions currently change the meaning of the pattern limit in compilation and translation. On current main, this documented unlimited call raises PatternLimitException:

from wcmatch import fnmatch

fnmatch.compile(["a", "{b,c}"], flags=fnmatch.BRACE, limit=0, exclude="x")

Changing the limit to 1 has the opposite problem: the call succeeds even though the exclusion already consumes the entire allowance. Subtracting the exclusion count changes the original limit to zero, which means unlimited.

Keep the original limit, count compiled exclusions toward the total, and reduce the brace-expansion allowance only for positive limits. This fixes the shared compilation/translation paths used by fnmatch and glob. Add regressions for strings and bytes, unlimited limits (0 and the existing negative-limit behavior), exhausted limits, exact boundaries, and exclusion-only input. Include an Unreleased changelog entry.

Validation on Windows / Python 3.11:

  • Before the fix: 16 new regression cases fail; the boundary controls pass.
  • After: python -m pytest -q — 1,282 passed, 167 skipped, 12 subtests passed. The unmodified checkout had 1,258 passed and the same skips.
  • python -m ruff check ., python -m mypy, and git diff --check pass.

Prepared with Codex; the reproduction and checks were run locally. Please preserve the Rexyysilent author attribution and Codex co-author trailer when merging.

Preserve the original limit while counting exclusions toward the total.
Only reduce the brace-expansion allowance for positive limits. This keeps
unlimited expansion unlimited and prevents an exhausted finite budget
from turning into the zero sentinel.

Add string and bytes regression coverage for compilation and translation,
including exact-limit and exclusion-only controls.

The model_string below is a user-requested custom attribution label,
not verified runtime model metadata.

model_string: OpenAI_DaybreakAstra
Co-authored-by: Codex <noreply@openai.com>
@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: docs Related to documentation. C: pattern-parser Related to pattern parsing. C: source Related to source code. C: tests Related to testing. labels Oct 17, 2026
@facelessuser

Copy link
Copy Markdown
Owner

This is a good catch. Appreicate the PR.

@gir-bot lgtm

@gir-bot gir-bot added S: approved The pull request is ready to be merged. and removed S: needs-review Needs to be reviewed and/or approved. labels Oct 17, 2026
@facelessuser
facelessuser merged commit ba92693 into facelessuser:main Oct 17, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: docs Related to documentation. C: pattern-parser Related to pattern parsing. C: source Related to source code. C: tests Related to testing. S: approved The pull request is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants