[Python-ideas] Making it easy to prepare for PEP479

Steven D'Aprano steve at pearwood.info
Mon May 18 16:52:25 CEST 2015


On Mon, May 18, 2015 at 10:17:06AM -0400, Terry Reedy wrote:

> Try the following: add the future statement to the top of modules with 
> generators, compile with 3.5, and when successful, comment-out the 
> statement.  For continued testing, especially with multiple authors, 
> write functions to un-comment and re-comment a file.  In the test file:
> 
> if <3.5>: uncomment('xyz')  # triggers re-compile on import
> import xyz
> if <3.5>: recomment('xyz')  # ditto,
> 
> If this works, put pep479_helper on pypi.

o_O

I'm not entirely sure what you are trying to do, but I *think* what you 
are trying is to have the byte code in the .pyc file be different from 
what the source code in the .py file says.

Fortunately Python does not make that easy to do. You would have to 
change the datestamp on the files so that the .pyc file appears newer 
than the source code.

I once worked on a system where it was easy to get the source and byte 
code out of sync. The original programmer was a frustrated C developer, 
and so he had built this intricate system where you edited the source 
code in one place, then ran the Unix "make" utility which compiled it, 
and moved the byte code to a completely different place on the 
PYTHONPATH. Oh, and you couldn't just run the Python modules as scripts, 
you had to run bash wrapper scripts which set up a bunch of environment 
variables. And of course there was no documentation other than rants 
about how stupid Python was but at least it was better than Perl. 
Believe me, debugging code where the byte code being imported is 
different from the source code you are reading is fun, if your idea of 
fun is horrible pain.


-- 
Steve


More information about the Python-ideas mailing list