Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99810

activestate recipe for code to source and back fails on 3.3+, core Python bug?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Newsgroups comp.lang.python
Subject activestate recipe for code to source and back fails on 3.3+, core Python bug?
Date Tue, 1 Dec 2015 18:57:38 +0000
Lines 73
Message-ID <mailman.80.1448996307.14615.python-list@python.org> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de z0GJJWbx7VT8id4hRAH/1wCBlGGY+cXWShSiOmTGWLeA==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'subject:bug': 0.05; 'subject:code': 0.07; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple.': 0.09; 'bug': 0.10; 'output': 0.13; 'def': 0.13; 'subject: \n ': 0.15; '3.3.': 0.16; 'involved,': 0.16; 'new:': 0.16; 'offset,': 0.16; 'received:194.126': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'recipe': 0.16; 'reproduce': 0.16; 'skip:| 20': 0.16; 'subject:3.3': 0.16; 'subject:core': 0.16; 'subject:fails': 0.16; 'language': 0.19; 'windows': 0.20; '3.2': 0.22; 'dropped': 0.22; 'lawrence': 0.22; 'import': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'question': 0.27; 'idea': 0.28; 'follows': 0.29; 'inspect': 0.29; 'url:activestate': 0.29; 'reporting': 0.29; 'code': 0.30; 'language.': 0.32; 'class': 0.33; 'problem': 0.33; 'hopefully': 0.33; "i'll": 0.33; 'equal': 0.34; 'url:code': 0.34; 'gets': 0.35; 'skip:c 30': 0.35; 'but': 0.36; 'list,': 0.36; 'skip:i 20': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'method': 0.37; 'received:org': 0.37; 'test': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'called': 0.40; 'field': 0.60; 'impact': 0.61; 'received:194': 0.61; 'yes': 0.62; 'our': 0.64; 'here': 0.66; 'below.': 0.66; 'analysis': 0.72; 'old,': 0.83; '3.6': 0.84; 'inclusive': 0.84; 'pythonistas,': 0.84; 'skip:| 10': 0.84; 'subject:source': 0.84; 'url:recipes': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host 107.93.126.194.pool.dsl.daisyplc.net
X-Mozilla-News-Host news://news.gmane.org
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:99810

Show key headers only | View raw


The recipe in question is here 
http://code.activestate.com/recipes/578353-code-to-source-and-back. 
I've called it c2sab in the test code below.

The problem is that the class name gets dropped during the round trip, 
but only if a list, dict or set comprehension or a generator expression 
is involved, and only from the code.co_consts tuple.  Hopefully the code 
and output that follows makes sense.

<code>
import c2sab
import inspect

class Comps():

     def listcomp(self):
         self.lc = [x for x in range(10)]

     def genexpr(self):
         self.ge = (x for x in range(10))

     def dictcomp(self):
         self.dc = {x: x**2 for x in range(10)}

     def setcomp(self):
         self.sc = {x for x in range(10)}

methods = inspect.getmembers(Comps, inspect.isfunction)
for _, method in methods:
     print('Processing', method.__name__)
     code = method.__code__
     recode = c2sab.recompile(*c2sab.uncompile(code))
     for offset, co_consts in enumerate(zip(code.co_consts, 
recode.co_consts)):
         old = co_consts[0]
         new = co_consts[1]
         if old != new:
             print('offset {} code |{}| not equal to recode 
|{}|'.format(offset, old, new))
     print()
</code>

<output>
Processing dictcomp
offset 2 code |Comps.dictcomp.<locals>.<dictcomp>| not equal to recode 
|dictcomp.<locals>.<dictcomp>|

Processing genexpr
offset 2 code |Comps.genexpr.<locals>.<genexpr>| not equal to recode 
|genexpr.<locals>.<genexpr>|

Processing listcomp
offset 2 code |Comps.listcomp.<locals>.<listcomp>| not equal to recode 
|listcomp.<locals>.<listcomp>|

Processing setcomp
offset 2 code |Comps.setcomp.<locals>.<setcomp>| not equal to recode 
|setcomp.<locals>.<setcomp>|
</output>

I can reproduce the above on 3.3 to 3.6 inclusive on Windows 10.  This 
has no impact on 3.2 or lower as the field in question is new in 
co_consts for 3.3.

So is my analysis correct?  If yes I'll be reporting a bug although I've 
no idea what against, if no what have I overlooked?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

activestate recipe for code to source and back fails on 3.3+, core Python bug? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-01 18:57 +0000

csiph-web