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

Failure in test_string_literals: Unexpected amount of warnings #64

Closed
lysnikolaou opened this issue Apr 9, 2020 · 6 comments · Fixed by #67 or python/cpython#19962
Closed

Failure in test_string_literals: Unexpected amount of warnings #64

lysnikolaou opened this issue Apr 9, 2020 · 6 comments · Fixed by #67 or python/cpython#19962
Labels
3.9.0b1 Needs to be fixed/implemented until the 3.9.0b1 release

Comments

@lysnikolaou
Copy link
Member

Current Parser:

╰─ ./python       
Python 3.9.0a5+ (heads/pegen:99a8e2fa08, Apr  9 2020, 16:19:04) 
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import warnings
>>> with warnings.catch_warnings(record=True) as w:
...     warnings.simplefilter('always', category=DeprecationWarning)
...     eval("'''\n\\z'''")
... 
'\n\\z'
>>> len(w)
1

Pegen:

╰─ ./python -p new
Python 3.9.0a5+ (heads/pegen:99a8e2fa08, Apr  9 2020, 16:19:04) 
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import warnings
>>> with warnings.catch_warnings(record=True) as w:
...     warnings.simplefilter('always', category=DeprecationWarning)
...     eval("'''\n\\z'''")
... 
'\n\\z'
>>> len(w)
2
@gvanrossum
Copy link

Simpler repro (the eval is just confusing matters):

Old parser:

>>> '\z'
<stdin>:1: DeprecationWarning: invalid escape sequence \z
'\\z'
>>> 

New parser:

>>> '\z'
<stdin>:1: DeprecationWarning: invalid escape sequence \z
<stdin>:1: DeprecationWarning: invalid escape sequence \z
<stdin>:1: DeprecationWarning: invalid escape sequence \z
'\\z'
>>> 

@lysnikolaou
Copy link
Member Author

If we memoize the atom rule, this goes away, since this is only happening, because the parser tries to parse a string more than once, before it completely fails and it backtracks out of everything.

Should we do it?

@lysnikolaou
Copy link
Member Author

lysnikolaou commented Apr 9, 2020

It seems that there is another mismatch here, that I had missed.

Current Parser:

>>> with warnings.catch_warnings(record=True) as w:
...     eval("'''\n\\z'''")
... 
'\n\\z'
>>> w[0].lineno
1

Pegen:

>>> with warnings.catch_warnings(record=True) as w:
...     eval("'''\n\\z'''")
... 
'\n\\z'
>>> w[0].lineno
2

Not sure which is wrong.

@gvanrossum
Copy link

Neither points to the line with the offending \z on it -- the old parser points to the start of the string, the new parser to the end. Let's say that the old parser is right then.

@lysnikolaou
Copy link
Member Author

lysnikolaou commented Apr 14, 2020

Reopening this until we disable the line checking test.

@lysnikolaou lysnikolaou reopened this Apr 14, 2020
@lysnikolaou lysnikolaou added the 3.9.0b1 Needs to be fixed/implemented until the 3.9.0b1 release label Apr 28, 2020
@lysnikolaou
Copy link
Member Author

Turns out pegen does not point to the end of the string, but to the ENDMARKER token here. The problem is that STRING nodes are parsed in a loop, which means that p->fill - 1 in
https://github.com/python/cpython/blob/531d1e541284bfd7944f8c66a5e8c3c3234afaff/Parser/pegen/pegen.c#L389 will always point to the node after a STRING, which I think is a bug and we need to find a way to resolve.

lysnikolaou added a commit to lysnikolaou/cpython that referenced this issue May 6, 2020
When parsing a string with an invalid escape, the old parser used to
point to the beginning of the invalid string. This PR changes the new
parser to match that behavior, since it's currently pointing to the
end of the string (or to be more precise, to the beginning of the next
token).

Closes we-like-parsers#64.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9.0b1 Needs to be fixed/implemented until the 3.9.0b1 release
Projects
None yet
2 participants