Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
_GSConverter: handle stray 'GS' in output gracefully#20473
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping@matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join uson gitter for real-time discussion.
For details on testing, writing docs, and our review process, please seethe developer guide
We strive to be a welcoming and open project. Please follow ourCode of Conduct.
raise ImageComparisonFailure( | ||
(err + b"GS" + stack + b">") | ||
.decode(sys.getfilesystemencoding(), "replace")) | ||
err = self._read_until((b"GS<", b"GS>")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
AFAICT_read_until
doesn't support tuples as is (len(terminator)
is wrong) and needs to be fixed to support them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You are correct, I was so happy about figuring out that.endswith()
accepts tuples that I've missed it ;-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok, so I've figured out that if instead of passing an explicit tuple, I use*terminator
arg, I can allow multiple terminators without having to actually change the call sites or having to add a compatibility hack. If you don't like that, I can revert to addingif not isinstance(terminator, tuple)
or changing all the call sites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Heh, wrong. I've just realized that stripping actually makes theerr.endswith()
test wrong :-/.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I guess you need aread_until(*terminator, include_terminator=False|True)
? Or just always include the terminator (returning a tuple for simpler use) and change all the call sites, perhaps that's slightly nicer APIwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ok, I think it's ready now. I've noticed another late-night mistake, and fixed it. I've aimed for minimal change / keeping the code simple now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I wonder if the whole thing would be simpler by having terminator be a regex instead, and returnmatch.groups()
? This way you can just matchr"GS(?:<(\d+))>"
instead of having to do two read_untils. (The slight extra cost of doing regex matches should be negligible compared to interacting with the subprocess.)
(If doing so, I would suggest having the argument be always acompiled regex object so that callers have to callre.compile
themselves to make it completely clear that the argument is a regex.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
To be honest, I don't really want to spend more time on it and I don't think it's really important how it's implemented given it's only used in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
no worries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks.
b605a5b
toff2b05c
CompareUh oh!
There was an error while loading.Please reload this page.
Search the GS output stream for either "GS<" or "GS>" explicitly ratherthan any "GS", in order to prevent the code from wrongly matching stray"GS". This fixes a recent test regression on Gentoo where the followingoutput seems to have been wrongly matched: **** Error 'gs' ignored -- ExtGState missing from Resources. ^^Fixesmatplotlib#20472
Thanks@mgorny ! Congratulations on your first Matplotlib PR merged 🎉 . Hopefully we will hear from you again. |
…473-on-v3.4.xBackport PR#20473 on branch v3.4.x (_GSConverter: handle stray 'GS' in output gracefully)
PR Summary
Search the GS output stream for either "GS<" or "GS>" explicitly rather
than any "GS", in order to prevent the code from wrongly matching stray
"GS". This fixes a recent test regression on Gentoo where the following
output seems to have been wrongly matched:
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).Fixes#20472