Document/correct hide_internal and store_locals

This commit is contained in:
rocky
2016-07-12 12:07:48 -04:00
parent b99f196d18
commit bc86b73cf0
4 changed files with 28 additions and 4 deletions

Binary file not shown.

View File

@@ -569,7 +569,7 @@ class Python3Parser(PythonParser):
class Python32Parser(Python3Parser):
def p_32(self, args):
"""
# Store locals is only in Python 3.2 and 3.3
# Store locals is only in Python 3.0 to 3.3
stmt ::= store_locals
store_locals ::= LOAD_FAST STORE_LOCALS
"""
@@ -577,7 +577,7 @@ class Python32Parser(Python3Parser):
class Python33Parser(Python3Parser):
def p_33(self, args):
"""
# Store locals is only in Python 3.2 and 3.3
# Store locals is only in Python 3.0 to 3.3
stmt ::= store_locals
store_locals ::= LOAD_FAST STORE_LOCALS

View File

@@ -137,7 +137,16 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.currentclass = None
self.classes = []
self.pending_newlines = 0
# hide_internal suppresses displaying the additional instructions that sometimes
# exist in code but but were not written in the source code.
# An example is:
# __module__ = __name__
# If showing source code we generally don't want to show this. However in fragment
# deparsing we generally do need to see these instructions since we may be stopped
# at one. So here we do not want to suppress showing such instructions.
self.hide_internal = False
self.name = None
self.offsets = {}
@@ -654,6 +663,12 @@ class FragmentsWalker(pysource.SourceWalker, object):
# find innermost node
if_node = None
comp_for = None
comp_designator = None
if n == 'comp_iter':
comp_for = n
comp_designator = ast[3]
while n in ('list_iter', 'comp_iter'):
n = n[0] # recurse one step
if n == 'list_for':
@@ -668,8 +683,9 @@ class FragmentsWalker(pysource.SourceWalker, object):
pass
pass
# Python 2.7+ starts including set_comp_body
# Python 3.5+ starts including setcomp_func
assert n.type in ('lc_body', 'comp_body', 'setcomp_func'), ast
assert n.type in ('lc_body', 'comp_body', 'setcomp_func', 'set_comp_body'), ast
assert designator, "Couldn't find designator in list/set comprehension"
old_name = self.name
@@ -686,7 +702,10 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.preorder(node[-3])
fin = len(self.f.getvalue())
self.set_pos_info(node[-3], start, fin, old_name)
if if_node:
if comp_designator:
self.preorder(comp_for)
elif if_node:
self.write(' if ')
self.preorder(if_node)
self.prec = p

View File

@@ -545,6 +545,11 @@ class SourceWalker(GenericASTTraversal, object):
self.currentclass = None
self.classes = []
self.pending_newlines = 0
# hide_internal suppresses displaying the additional instructions that sometimes
# exist in code but but were not written in the source code.
# An example is:
# __module__ = __name__
self.hide_internal = True
self.name = None
self.version = version