Issue 15627: Add a method to importlib.abc.SourceLoader for converting source to a code object (original) (raw)

Created on 2012-08-12 00:44 by brett.cannon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (11)
msg168015 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-08-12 00:44
A classmethod called importlib.abc.SourceLoader.source_to_code(source_bytes, path) would return a code object. By default it would be equivalent to ``compile(source_bytes, source_path, 'exec', dont_inherit=True)``, but others could override this to e.g. convert the source to an AST, optimize the AST, and then call compile() to get the desired code object.
msg175635 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-11-15 19:57
Might name this compile_source() instead.
msg175658 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-11-15 23:53
Though I haven't been able to get to this, I do have a demo of sorts that I've been using elsewhere: https://bitbucket.org/ericsnowcurrently/pylt/src/default/pylt/_importing.py?at=default#cl-225
msg175760 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-11-17 15:54
We might want an keyword-only 'optimize' argument that maps to the compile() function's 'optimize' argument.
msg175876 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-11-18 15:03
New changeset e30bcce5c634 by Brett Cannon in branch 'default': Issue #15627: Add the compile_source() method to http://hg.python.org/cpython/rev/e30bcce5c634
msg176521 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-11-28 07:48
Sorry, just now digging out of a massive backlog here. The originally proposed name of "source_to_code()" might be more appropriate than compile_source(). The relationship to compilation is not compulsory and the name/docstring/docs might imply that. If you're not opposed, Brett, I can make the change. Regardless, glad to see this in. :)
msg176554 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-11-28 17:06
It might not be compulsory, but how else are you going to get a code object? Then again, get_code() kind of codifies the use of the word "code" for methods that return a code object. So if you want to do the work to change the name then go ahead.
msg176970 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-12-05 07:53
New changeset 7caab48f171e by Eric Snow in branch 'default': Issue #15627: This is simply an update to the name of a new method recently added http://hg.python.org/cpython/rev/7caab48f171e
msg185589 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-03-30 20:01
The first commit does something fishy with tests: http://hg.python.org/cpython/rev/e30bcce5c634#l3.1
msg185596 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-03-30 22:37
It cleans up the run_unittest() call. You can check the file and see that the "missing" classes are actually not in the module anymore.
msg185641 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-03-31 18:45
Ah, okay. I can’t wait for the time when unittest.main() is used everywhere and we delete run_unittest :)
History
Date User Action Args
2022-04-11 14:57:34 admin set github: 59832
2013-03-31 18:45:58 eric.araujo set messages: +
2013-03-30 22:37:26 brett.cannon set messages: +
2013-03-30 20:01:42 eric.araujo set nosy: + eric.araujomessages: +
2012-12-05 07:53:12 python-dev set messages: +
2012-11-28 17:06:15 brett.cannon set messages: +
2012-11-28 07:48:37 eric.snow set messages: +
2012-11-18 20:46:48 Arfrever set stage: test needed -> resolved
2012-11-18 15:23:10 brett.cannon set status: open -> closeddependencies: - Document the 'optimize' argument to compile()resolution: fixed
2012-11-18 15:03:46 python-dev set nosy: + python-devmessages: +
2012-11-17 15:54:57 brett.cannon set dependencies: + Document the 'optimize' argument to compile()messages: +
2012-11-15 23:53:03 eric.snow set messages: +
2012-11-15 19:57:27 brett.cannon set messages: +
2012-09-14 19:33:54 Julian set nosy: + Julian
2012-08-17 16:20:01 asvetlov set nosy: + asvetlov
2012-08-13 19:36:57 brett.cannon set assignee: brett.cannon
2012-08-12 21:33:44 meador.inge set nosy: + meador.inge
2012-08-12 18:16:20 Arfrever set nosy: + Arfrever
2012-08-12 12:36:37 yselivanov set nosy: + yselivanov
2012-08-12 00:44:36 brett.cannon create