Skip to content

Honour character ranges in MANIFEST.in exclude patterns - #5374

Open
andrewstellman wants to merge 3 commits into
pypa:mainfrom
andrewstellman:char-class-ranges
Open

andrewstellman wants to merge 3 commits into
pypa:mainfrom
andrewstellman:char-class-ranges

Conversation

@andrewstellman

Copy link
Copy Markdown

Summary of changes

With graft keys and exclude keys/[a-z].pem in MANIFEST.in, the sdist still contains keys/b.pem. translate_pattern passes the inside of a [...] class through re.escape, so - is literal and [a-c] matches only a, - and c, although the docs say ranges such as [a-z] are supported and include honours them. The fix leaves - unescaped inside the class, and two new translate_specs entries cover [a-c] and [!a-c].

Found with the Quality Playbook, an AI code-review tool I maintain. The fix and test were written with AI assistance and reviewed by me.

Pull Request Checklist

  • Changes have tests
  • News fragment added in newsfragments/.

translate_pattern escaped the inside of a [...] class with re.escape, so
"-" was literal and [a-c] matched only "a", "-" and "c".

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global hyphen replacement also turns a reversed class such as key[z-a].pem into the regex [z-a], which re.compile rejects as a bad character range. Before this change the hyphen was escaped, so this pattern did not abort MANIFEST.in file-list generation. Could the translator handle invalid range endpoints without an uncaught regex error, with a regression for this case? I reviewed the current diff; I did not run the test suite locally.

Like fnmatch, a reversed range such as [z-a] now matches nothing
instead of raising re.error.
@andrewstellman

Copy link
Copy Markdown
Author

@agammann Thanks, good catch. Reversed ranges are now dropped the way fnmatch drops them, so key[z-a].pem matches nothing instead of raising, [!z-a] matches any character and [z-ab] still matches b. All three are in translate_specs. I also renamed the news fragment to the PR number.

@agammann

Copy link
Copy Markdown

Thanks for the update. I rechecked head 4a713c8: reversed ranges are removed before the regex is built, and the added cases cover the empty, negated, and mixed classes I was concerned about. That addresses the uncaught regex error I raised. I reviewed the diff and did not run the project test suite. AI-assisted review.

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.

2 participants