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

Fix parser when using Python 3.9 #8716

Merged
merged 3 commits into from Apr 25, 2020
Merged

Fix parser when using Python 3.9 #8716

merged 3 commits into from Apr 25, 2020

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Apr 23, 2020

The structure of the AST for subscripts was changed in
python/cpython#9605

Fixes #8627

Also fix the majority of the errors produced when running pytest with Python 3.9, but not all.

The structure of the AST for subscripts was changed in
python/cpython#9605

Fixes #8627
@gvanrossum
Copy link
Member Author

Hm, there are some errors in the 3.9 test run. Let me look into these.

@gvanrossum gvanrossum changed the title Fix parser when using Python 3.9 [WIP] Fix parser when using Python 3.9 Apr 23, 2020
@gvanrossum gvanrossum changed the title [WIP] Fix parser when using Python 3.9 Fix parser when using Python 3.9 Apr 24, 2020
@gvanrossum
Copy link
Member Author

Okay, there are some remaining Python 3.9 test failures, but they seem to be just cases where Python 3.9 somehow produces different output. Examples:

Expected:
  main:3: error: keyword argument repeated      (diff)
Actual:
  main:3: error: "f" gets multiple values for keyword argument "a" (diff)

(The new parser produces a better error message for duplicate keyword args.)

Also a few parse trees are different, e.g.:

Alignment of first line difference:
  E:       TupleExpr:-1(
  A:       TupleExpr:1(
                     ^

(The old parser didn't have a line or column number for certain Tuples.)

Finally:

Expected:
  Daemon started                                (diff)
  mypy-daemon: error: Missing target module, package, files, or command. (diff)
  == Return code: 2
Actual:
  mypy-daemon: error: Missing target module, package, files, or command. (diff)
  Daemon started                                (diff)
  == Return code: 2

Seems the two error lines are produced in a different order.

@@ -233,6 +233,8 @@ def clean_up(a: List[str]) -> List[str]:
remove trailing carriage returns.
"""
res = []
pwd = os.getcwd()
Copy link
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
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
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.

Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good!

I'm not actually sure if we have any kind of principled way to deal with version mismatches like this; I think we normally just hack around it... We could add -only_post_39 and -only_pre_39 magic test name suffixes to split_test_cases, I guess, or just disable or tweak the tests.

The daemon one is bizarre and probably needs real investigation; maybe its something involving the interleaving of stdout and stderr?

@gvanrossum
Copy link
Member Author

Merging now, we can iterate later.

@gvanrossum gvanrossum merged commit 125728a into master Apr 25, 2020
@gvanrossum gvanrossum deleted the fix39 branch April 25, 2020 00:57
@hauntsaninja hauntsaninja mentioned this pull request Apr 29, 2020
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Apr 29, 2020

Opened #8743 for fixing parse trees.
The full path name in the traceback is probably caused by https://bugs.python.org/issue20443 (as mentioned in 3.9's what's new).

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.

Update fastparse for 3.9 AST changes
3 participants