[pypy-commit] pypy py3.6: Test and fix: follow CPython (at least 3.6.9) in updating the line number
arigo
pypy.commits at gmail.com
Mon Jan 6 12:49:46 EST 2020
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.6
Changeset: r98452:d36692105171
Date: 2020-01-06 18:50 +0100
http://bitbucket.org/pypy/pypy/changeset/d36692105171/
Log: Test and fix: follow CPython (at least 3.6.9) in updating the line
number if it decides to constantify the whole tuple of default
arguments
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -394,8 +394,10 @@
return l
def _visit_defaults(self, defaults):
+ assert len(defaults) > 0
w_tup = self._tuple_of_consts(defaults)
if w_tup:
+ self.update_position(defaults[-1].lineno, True)
self.load_const(w_tup)
else:
self.visit_sequence(defaults)
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1255,6 +1255,27 @@
src = """# -*- coding: utf-8 -*-\nz=ord(fr'\xc3\x98')\n"""
yield self.st, src, 'z', 0xd8
+ def test_func_defaults_lineno(self):
+ # like CPython 3.6.9 (at least), check that '''def f(
+ # x = 5,
+ # y = 6,
+ # ):'''
+ # generates the tuple (5, 6) as a constant for the defaults,
+ # but with the lineno for the last item (here the 6). There
+ # is no lineno for the other items, of course, because the
+ # complete tuple is loaded with just one LOAD_CONST.
+ yield self.simple_test, """\
+ def fdl(): # line 1
+ def f( # line 2
+ x = 5, # line 3
+ y = 6 # line 4
+ ): # line 5
+ pass # line 6
+ import dis
+ co = fdl.__code__
+ x = [y for (x, y) in dis.findlinestarts(co)]
+ """, 'x', [4]
+
class TestCompilerRevDB(BaseTestCompiler):
spaceconfig = {"translation.reverse_debugger": True}
More information about the pypy-commit
mailing list