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

fuzzer: add special-case for multi-line EOF TokenError #1991

Merged
merged 10 commits into from
Feb 20, 2021
Merged

fuzzer: add special-case for multi-line EOF TokenError #1991

merged 10 commits into from
Feb 20, 2021

Conversation

jayaddison
Copy link
Contributor

@jayaddison jayaddison commented Feb 17, 2021

Goal: reduces test failure false-positives relating to #1012.

cc @Zac-HD

fuzz.py Outdated Show resolved Hide resolved
fuzz.py Outdated Show resolved Hide resolved
@jayaddison jayaddison changed the title Add special-case for multi-line EOF TokenError under Python3.7 fuzzer: add special-case for multi-line EOF TokenError Feb 17, 2021
@jayaddison jayaddison marked this pull request as draft February 17, 2021 16:05
fuzz.py Outdated
):
print('Warning: skipped fuzzer-generated input that contained a backslash')
print('See https://github.com/psf/black/issues/1012 for details')
print('To replay this fuzzer run, find the PYTHONHASHSEED environment value')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Zac-HD Could you confirm whether this is reasonable advice?

fuzz.py Outdated Show resolved Hide resolved
@Zac-HD
Copy link
Contributor

Zac-HD commented Feb 18, 2021

One challenge though: the EOF multi-line exception can occur for other versions of Python after all.

In a previous note I mentioned that Python 3.8+ do reject the "" (only a backslash) input - and that's true, but Python3.8 will also compile '#\n\\\r\n', for example, which black rejects with the EOF multi-line TokenError.

Ah. If we're not just waiting out the end-of-life for Python 3.7, I think there's an actual bug which should be fixed.

Concretely for this PR though, I'd just remove the version-check and change the comment to explain that we're suppressing a known bug and will fix it later.

@jayaddison
Copy link
Contributor Author

jayaddison commented Feb 18, 2021

Is there an existing upstream issue that we can link to here, or perhaps we should create one?

(my thinking is that we should add a note/reference upstream to remind us to clean this workaround up once the root cause is resolved)

@Zac-HD
Copy link
Contributor

Zac-HD commented Feb 18, 2021

I think the bug is in Black - Hypothesmith is generating source code which is valid according to the compile() builtin, and if Black can't handle it the bug is in Black's tokenisation, not upstream.

If you think it is upstream, where is it and how should it be fixed?

@jayaddison
Copy link
Contributor Author

Ok, yep. It does follow logically that this is most likely a bug in black. I'll update the explanatory comment accordingly.

@jayaddison jayaddison marked this pull request as ready for review February 18, 2021 22:53
@ichard26 ichard26 self-requested a review February 19, 2021 02:27
fuzz.py Outdated
import hypothesmith
from hypothesis import HealthCheck, given, settings, strategies as st

import black
from blib2to3.pgen2.tokenize import ( # NB: This intends to (and currently does) import the black-vendored blib2to3
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this comment based on a memory of reading some code that variously imported either the blib2to3 code or Python's built-in lib2to3 code. But after checking it again, I realize they use different module names, so I think this comment is redundant and can be removed.

Copy link
Contributor

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

Looks good to me - thanks, @jayaddison!

@jayaddison
Copy link
Contributor Author

Thanks @ichard26, @Zac-HD!

@cooperlees
Copy link
Collaborator

This is awesome work all. @jayaddison - Appreciate all your efforts, I know I haven't been around much. But appreciate the deep debugging and pulling these PRs together!

@cooperlees cooperlees merged commit 306a513 into psf:master Feb 20, 2021
@jayaddison
Copy link
Contributor Author

No worries, thanks @cooperlees!

@jayaddison jayaddison deleted the tests/skip-eof-tokenization-error branch February 20, 2021 16:54
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.

4 participants