Fix parser when using Python 3.9 by gvanrossum · Pull Request #8716 · python/mypy · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions mypy/fastparse.py
4 changes: 4 additions & 0 deletions mypy/test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def clean_up(a: List[str]) -> List[str]:
remove trailing carriage returns.
"""
res = []
pwd = os.getcwd()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What was going on here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Many tests suddenly showed the full pathname in the traceback instead of simply File "driver.py", line NNN. I don't actually know why, but I could imagine that somehow an absolute path was computed by Python where it previously believed the pathname on the command line? It's always about "driver.py" which I presume is the synthetic script created by the test harness.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Playing around, this just seems new behavior in Python 3.9, so I think my fix is the best we can do.

driver = pwd + '/driver.py'
for s in a:
prefix = os.sep
ss = s
Expand All @@ -241,6 +243,8 @@ def clean_up(a: List[str]) -> List[str]:
ss = ss.replace(p, '')
# Ignore spaces at end of line.
ss = re.sub(' +$', '', ss)
# Remove pwd from driver.py's path
ss = ss.replace(driver, 'driver.py')
res.append(re.sub('\\r$', '', ss))
return res

Expand Down
5 changes: 4 additions & 1 deletion mypyc/test-data/run.test