classification
Title: Add a method to importlib.abc.SourceLoader for converting source to a code object
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: Arfrever, Julian, asvetlov, brett.cannon, eric.araujo, eric.snow, meador.inge, python-dev, yselivanov
Priority: low Keywords:

Created on 2012-08-12 00:44 by brett.cannon, last changed 2013-03-31 18:45 by eric.araujo. 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) 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) 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
2013-03-31 18:45:58eric.araujosetmessages: + msg185641
2013-03-30 22:37:26brett.cannonsetmessages: + msg185596
2013-03-30 20:01:42eric.araujosetnosy: + eric.araujo
messages: + msg185589
2012-12-05 07:53:12python-devsetmessages: + msg176970
2012-11-28 17:06:15brett.cannonsetmessages: + msg176554
2012-11-28 07:48:37eric.snowsetmessages: + msg176521
2012-11-18 20:46:48Arfreversetstage: test needed -> resolved
2012-11-18 15:23:10brett.cannonsetstatus: open -> closed
dependencies: - Document the 'optimize' argument to compile()
resolution: fixed
2012-11-18 15:03:46python-devsetnosy: + python-dev
messages: + msg175876
2012-11-17 15:54:57brett.cannonsetdependencies: + Document the 'optimize' argument to compile()
messages: + msg175760
2012-11-15 23:53:03eric.snowsetmessages: + msg175658
2012-11-15 19:57:27brett.cannonsetmessages: + msg175635
2012-09-14 19:33:54Juliansetnosy: + Julian
2012-08-17 16:20:01asvetlovsetnosy: + asvetlov
2012-08-13 19:36:57brett.cannonsetassignee: brett.cannon
2012-08-12 21:33:44meador.ingesetnosy: + meador.inge
2012-08-12 18:16:20Arfreversetnosy: + Arfrever
2012-08-12 12:36:37yselivanovsetnosy: + yselivanov
2012-08-12 00:44:36brett.cannoncreate