Can't add a new keyword to Python
Asked Answered
C

0

6

I tried to add a new keyword (a new flow statement) to Python, by following this blog post and this PEP. I'm pretty sure I've added what I needed to add to the right places, according to the PEP that I've mentioned. These are the files that I've modified:

Grammar/Grammar
Parser/Python.asdl
Python/ast.c
Python/Python-ast.c
Python/Python-ast.h
Python/symbtable.c
Python/compile.c

I'm doing this on Windows, so instead of running make, I ran PCbuild/build.bat. The build seemed to be successful. However, when I ran the freshly-built python.exe, my keyword was not recognized (got NameError: name [...] is not defined).

As a sanity test, I tried to remove the break statement from Python by deleting break_stmt from Grammar/Grammar and rerunning PCbuild/build.bat. The break statement worked just fine, which means that the removal has failed.

I've also noticed that the files Include/graminit.c and Include/graminit.h were not regenerated, and, according to the PEP that I've mentioned, it should have been done by pgen, which was supposed to be called by make. But as I've mentioned earlier, I ran PCbuild/build.bat, and not make. I tried to run pgen manually, but it failed with the exception ImportError: attempted relative import with no known parent package.

So, since the removal of a keyword has also failed, I think that my custom Python was not built properly (even though the build appears to be successful and it generates a working python.exe). What might be causing this?

EDIT: I've also tried to delete the file Grammar/Grammar and rebuild, and the build still worked. Something's not right.

Cobra answered 14/6, 2019 at 16:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.