Skip to content

bpo-37001: Makes symtable.symtable have parity with compile for input#13483

Merged
DinoV merged 6 commits intopython:masterfrom
DinoV:dinov/symtable
May 28, 2019
Merged

bpo-37001: Makes symtable.symtable have parity with compile for input#13483
DinoV merged 6 commits intopython:masterfrom
DinoV:dinov/symtable

Conversation

@DinoV
Copy link
Copy Markdown
Contributor

@DinoV DinoV commented May 22, 2019

This PR modifies symtable.symtable() to allow bytes objects as source input similar to how they're accepted in compile().

Currently if you were parsing code with ast.parse(), and attempting to understand the name bindings with symtable.symtable(), you have one of two options:
1) Only accept strings
2) Use the tokenize module to go through a separate code path to attempt to parse the PEP 263 coding string.

Given that symtable.symtable ultimately goes down to the same underlying APIs as compile() it seems silly to require these extra steps. So this unifies exec/eval/compile/symtable.symtable to use a single code path (_Py_SourceAsString) for doing the conversion. This is the same as the existing source_as_string which is simply renamed and moved in with the other various parsing functions.

https://bugs.python.org/issue37001

@the-knights-who-say-ni
Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@gvanrossum gvanrossum removed their request for review May 24, 2019 18:06
@gvanrossum
Copy link
Copy Markdown
Member

Sorry, I don't review C code any more. Hopefully Serhiy will review this. Good luck!

Comment thread Modules/symtablemodule.c Outdated
_symtable.symtable

str: str
str: object
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest to rename str to source.

Comment thread Modules/symtablemodule.c
}
t = (PyObject *)st->st_top;
Py_INCREF(t);
PyMem_Free((void *)st->st_future);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Leaked source_copy.

rename str->source - lso matching compile, after verifying
  we don't currently accept kw arguments
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM, but you need to regenerate generated files. make regen-all

@@ -0,0 +1,2 @@
symtable.symtable now accepts the same input types for source code as the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
symtable.symtable now accepts the same input types for source code as the
:func:`symtable.symtable` now accepts the same input types for source code as the

@@ -0,0 +1,2 @@
symtable.symtable now accepts the same input types for source code as the
built-in compile function.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
built-in compile function.
built-in :func:`compile` function.

@DinoV DinoV merged commit 4154069 into python:master May 28, 2019
@bedevere-bot
Copy link
Copy Markdown

@DinoV: Please replace # with GH- in the commit message next time. Thanks!

DinoV added a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
…python#13483)

* Makes symtable.symtable have parity for accepted datatypes
for source code as compile()

* Add NEWS blurb
@DinoV DinoV deleted the dinov/symtable branch May 31, 2024 18:24
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.

5 participants