[pypy-commit] pypy py3.5: __annotations__ takes keys that are mangled parameter names
arigo
pypy.commits at gmail.com
Sat Dec 3 03:04:50 EST 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88838:5eca897303d3
Date: 2016-12-03 09:04 +0100
http://bitbucket.org/pypy/pypy/changeset/5eca897303d3/
Log: __annotations__ takes keys that are mangled parameter names
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
@@ -345,7 +345,7 @@
def _visit_arg_annotation(self, name, ann, names):
if ann:
ann.walkabout(self)
- names.append(name)
+ names.append(self.scope.mangle(name))
def _visit_arg_annotations(self, args, names):
if args:
diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -60,6 +60,13 @@
f.__annotations__ = ann
assert f.__annotations__ is ann
+ def test_annotations_mangle(self): """
+ class X:
+ def foo(self, __a:5, b:6):
+ pass
+ assert X.foo.__annotations__ == {'_X__a': 5, 'b': 6}
+ """
+
def test_kwdefaults(self):
"""
def f(*, kw=3): return kw
More information about the pypy-commit
mailing list