Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-107715: Escape class name in regular expression #107716

Merged

Conversation

gertjanvanzwieten
Copy link
Contributor

@gertjanvanzwieten gertjanvanzwieten commented Aug 7, 2023

Fixes #107715. This patch escapes the class name before embedding it in the regular expression for pat in doctest.DocTestFinder._find_lineno. While class names do not ordinarily contain special characters, it is possible to encounter these when a class is created dynamically. Escaping the name will correctly return None in this scenario, rather than potentially matching a different class or raising re.error depending on the symbols used.

This patch escapes the class name before embedding it in the regular expression
for `pat` in `doctest.DocTestFinder._find_lineno`. While class names do not
ordinarily contain special characters, it is possible to encounter these when a
class is created dynamically. Escaping the name will correctly return `None` in
this scenario, rather than potentially matching a different class or raising
`re.error` depending on the symbols used.
@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Aug 7, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@gertjanvanzwieten
Copy link
Contributor Author

gertjanvanzwieten commented Aug 7, 2023

CLA signing fails repeatedly with internal server error, and the bedevere/news action does not appear to recognize the news entry. Edit: both issues seem to have resolved themselves.

gertjanvanzwieten added a commit to evalf/nutils that referenced this pull request Aug 7, 2023
This patch changes doctest's test finder to include all files in the nutils
directory, rather than the ones listed in nutils.__all__ which is due to be
removed. The change includes a modified version of DocTestFinder to fix a bug
triggered by the SI module (formerly untested) and for which a PR is created
for cpython (python/cpython#107716). The patch also
includes a small fix in SI's documentation.
@serhiy-storchaka serhiy-storchaka merged commit 8579327 into python:main Aug 7, 2023
24 checks passed
@serhiy-storchaka serhiy-storchaka added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Aug 7, 2023
@gertjanvanzwieten gertjanvanzwieten deleted the doctest-escape-classname branch August 7, 2023 15:25
@miss-islington
Copy link
Contributor

Thanks @gertjanvanzwieten for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @gertjanvanzwieten for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 7, 2023
…7716)

This patch escapes the class name before embedding it in the regular expression
for `pat` in `doctest.DocTestFinder._find_lineno`. While class names do not
ordinarily contain special characters, it is possible to encounter these when a
class is created dynamically. Escaping the name will correctly return `None` in
this scenario, rather than potentially matching a different class or raising
`re.error` depending on the symbols used.
(cherry picked from commit 8579327)

Co-authored-by: Gertjan van Zwieten <git@gjvz.nl>
@bedevere-bot
Copy link

GH-107726 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Aug 7, 2023
@bedevere-bot
Copy link

GH-107727 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 7, 2023
…7716)

This patch escapes the class name before embedding it in the regular expression
for `pat` in `doctest.DocTestFinder._find_lineno`. While class names do not
ordinarily contain special characters, it is possible to encounter these when a
class is created dynamically. Escaping the name will correctly return `None` in
this scenario, rather than potentially matching a different class or raising
`re.error` depending on the symbols used.
(cherry picked from commit 8579327)

Co-authored-by: Gertjan van Zwieten <git@gjvz.nl>
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Aug 7, 2023
gertjanvanzwieten added a commit to evalf/nutils that referenced this pull request Aug 7, 2023
This patch changes doctest's test finder to include all files in the nutils
directory, rather than the ones listed in nutils.__all__ which is due to be
removed. The change includes a modified version of DocTestFinder to fix a bug
triggered by the SI module (formerly untested) and for which a fix is pending
for cpython (python/cpython#107716). The patch also
includes a small fix in SI's documentation.
serhiy-storchaka pushed a commit that referenced this pull request Aug 12, 2023
…GH-107727)

This patch escapes the class name before embedding it in the regular expression
for `pat` in `doctest.DocTestFinder._find_lineno`. While class names do not
ordinarily contain special characters, it is possible to encounter these when a
class is created dynamically. Escaping the name will correctly return `None` in
this scenario, rather than potentially matching a different class or raising
`re.error` depending on the symbols used.
(cherry picked from commit 8579327)

Co-authored-by: Gertjan van Zwieten <git@gjvz.nl>
Yhg1s pushed a commit that referenced this pull request Aug 16, 2023
…#107726)

* gh-107715: Escape class name in regular expression (GH-107716)

This patch escapes the class name before embedding it in the regular expression
for `pat` in `doctest.DocTestFinder._find_lineno`. While class names do not
ordinarily contain special characters, it is possible to encounter these when a
class is created dynamically. Escaping the name will correctly return `None` in
this scenario, rather than potentially matching a different class or raising
`re.error` depending on the symbols used.
(cherry picked from commit 8579327)

Co-authored-by: Gertjan van Zwieten <git@gjvz.nl>

* Update 2023-08-07-14-12-07.gh-issue-107715.238r2f.rst

---------

Co-authored-by: Gertjan van Zwieten <git@gjvz.nl>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
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.

DocTestFinder.find fails if module contains class objects with special characters
4 participants