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

mdx_gist: inherit from InlineProcessor, work on Python 3.11 (#3630) #3631

Merged
merged 2 commits into from
Jun 21, 2022

Conversation

AdamWill
Copy link
Contributor

The gist-rst pattern crashes Python 3.11, because its pattern
tries to set the multiline flag - it starts with (?m) - but
Markdown's Pattern class __init__, which is called by our
GistPattern.__init__, 'wraps' the pattern with additional
capture groups before compiling it. This causes the multiline
flag not to be at the start of the 'wrapped' pattern. From
Python 3.6 to Python 3.10 flags not being at the start of the
pattern was deprecated and triggered a warning when trying to
compile it; in Python 3.11 it's an error.

Markdown 3.0.0 added a preferred InlineProcessor class:
Python-Markdown/markdown#629
which does not do this wrapping. It requires the subclass to
implement handleMatch, which we already do. Our handleMatch
uses named capture groups, so the change in the number of
capture groups in the compiled expression shouldn't matter. So
simply switching to inheriting from InlineProcessor instead
of Pattern should solve the problem.

We already required Markdown 3.0.0, so this does not mean we
require a newer Markdown than before.

Signed-off-by: Adam Williamson awilliam@redhat.com

Pull Request Checklist

  • I’ve read the guidelines for contributing.
  • [-] I updated AUTHORS.txt and CHANGES.txt (if the change is non-trivial) and documentation (if applicable).
  • I tested my changes.

Description

Change seems fairly trivial and should not be visible to users, so I didn't bother with AUTHORS and CHANGES. I've 'tested' this insofar as nikola now at least passes its own test suite with Python 3.11 (it did not before); the test suite does not seem to cover this file, so I don't think we'll know if it's broken, but I don't think it should be.

…a#3630)

The gist-rst pattern crashes Python 3.11, because its pattern
tries to set the multiline flag - it starts with `(?m)` - but
Markdown's `Pattern` class `__init__`, which is called by our
`GistPattern.__init__`, 'wraps' the pattern with additional
capture groups before compiling it. This causes the multiline
flag not to be at the start of the 'wrapped' pattern. From
Python 3.6 to Python 3.10 flags not being at the start of the
pattern was deprecated and triggered a warning when trying to
compile it; in Python 3.11 it's an error.

Markdown 3.0.0 added a preferred `InlineProcessor` class:
Python-Markdown/markdown#629
which does not do this wrapping. It requires the subclass to
implement `handleMatch`, which we already do. Our `handleMatch`
uses named capture groups, so the change in the number of
capture groups in the compiled expression shouldn't matter. So
simply switching to inheriting from `InlineProcessor` instead
of `Pattern` (and slightly adjusting the signature and return
values to match what's expected of `InlineProcessor` subclasses)
should solve the problem.

We already required Markdown 3.0.0, so this does not mean we
require a newer Markdown than before.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
@Kwpolska
Copy link
Member

Thanks for contributing this fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants