Skip to content

Refix for pyparsing compat. #21501

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

Merged
merged 1 commit into from
Nov 14, 2021
Merged

Refix for pyparsing compat. #21501

merged 1 commit into from
Nov 14, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 29, 2021

PR Summary

cf #21489 (comment) (@ptmcg I'm not super certain about the expected semantics, but the need to explicitly skip whitespace here looks like a bug to me?)

For master, I think #21448 also fixes that.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@anntzer anntzer added this to the v3.5.0 milestone Oct 29, 2021
@@ -2060,6 +2060,7 @@ def __init__(self):
p.accent <<= Group(
Suppress(p.bslash)
+ oneOf([*self._accent_map, *self._wide_accents])
+ Suppress(Optional(White()))
Copy link

@ptmcg ptmcg Oct 29, 2021

Choose a reason for hiding this comment

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

If the code is not working without this explicit whitespace-skipping, that is a pyparsing bug. Since you have made it Optional, then this won't break once the pyparsing bug is fixed. (You can also - or at least should be able to - use Empty() as a synonym for Suppress(Optional(White()))

Copy link

Choose a reason for hiding this comment

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

Ok. There is a bug in pyparsing, but fixing it doesn't completely solve your problem.

What is the purpose of leaveWhitespace() here?

    p.symbol        <<= (p.single_symbol | p.symbol_name).leaveWhitespace()

It looks like this is the only element in p.placeable that suppresses whitespace-skipping. The new code detects this and instead of doing whitespace-skipping before the MatchFirst, it doesn't do whitespace-skipping, relying on all the separate elements to do it themselves (this is the performance optimization - if all the alternatives will want whitespace to be skipped, the MatchFirst will do it once, and then all the alternatives get a pass). Since p.symbol suppresses whitespace-skipping, and so makes p.placeable suppress whitespace-skipping, then when it is time to match p.symbol, the leading space has not been skipped, and so it fails.

So:

  • I need to fix the bug in pyparsing - this will be in 3.0.4, which I will push out this evening.

  • This is another pyparsing improvement that needs to be documented in the "stuff that has changed for the better, but may affect your code" - I'll add that information in 3.0.4 also.

  • Please revisit why you need to have leaveWhitespace() on p.symbol.

    If it is required, then I think you could remove the Suppress(Optional(White())) from p.accent, and instead change the p.symbol usage in p.placeable to:

      | Empty() + p.symbol  # Must be third to catch all named symbols and single
    

    (I tested this in my minimal repro example and that works.)
    But ideally, you could just remove the call to leaveWhitespace().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed that removing leaveWhitespace seems to work; looking at the git history it seems to be a historical artefact of the times when symbol and symbol_name were not split, and was used for symbol_name.

@jklymak jklymak modified the milestones: v3.5.0, v3.5.1 Nov 11, 2021
@tacaswell tacaswell modified the milestones: v3.5.1, v3.5.0 Nov 11, 2021
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Nov 11, 2021
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

@anntzer are you in agreement that this should go in as-is and be back ported per @tacaswell analysis in #21606?

@anntzer
Copy link
Contributor Author

anntzer commented Nov 14, 2021

Yes per #21606 (comment).

@jklymak jklymak merged commit 1127632 into matplotlib:main Nov 14, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Nov 14, 2021
@anntzer anntzer deleted the p3b branch November 14, 2021 20:41
timhoffm added a commit that referenced this pull request Nov 14, 2021
…501-on-v3.5.x

Backport PR #21501 on branch v3.5.x (Refix for pyparsing compat.)
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Apr 1, 2022
We missed relaxing the requirement in
matplotlib#21501
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: text/mathtext
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants