diff -r 1166b3321012 Lib/test/test_grammar.py --- a/Lib/test/test_grammar.py Thu Feb 13 12:48:54 2014 +0100 +++ b/Lib/test/test_grammar.py Fri Feb 14 14:15:37 2014 -0500 @@ -314,6 +314,13 @@ self.assertEqual(f.__annotations__, {'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9, 'k': 11, 'return': 12}) + # Check for issue #20625 -- annotations mangling + class Spam: + def f(self, *, __kw:1): + pass + class Ham(Spam): pass + self.assertEquals(Spam.f.__annotations__, {'_Spam__kw': 1}) + self.assertEquals(Ham.f.__annotations__, {'_Spam__kw': 1}) # Check for SF Bug #1697248 - mixing decorators and a return annotation def null(x): return x @null diff -r 1166b3321012 Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py Thu Feb 13 12:48:54 2014 +0100 +++ b/Lib/test/test_inspect.py Fri Feb 14 14:15:37 2014 -0500 @@ -2390,6 +2390,22 @@ self.assertEqual(sig.return_annotation, 42) self.assertEqual(sig, inspect.signature(test)) + def test_signature_on_mangled_parameters(self): + class Spam: + def foo(self, __p1:1=2, *, __p2:2=3): + pass + class Ham(Spam): + pass + + self.assertEqual(self.signature(Spam.foo), + ((('self', ..., ..., "positional_or_keyword"), + ('_Spam__p1', 2, 1, "positional_or_keyword"), + ('_Spam__p2', 3, 2, "keyword_only")), + ...)) + + self.assertEqual(self.signature(Spam.foo), + self.signature(Ham.foo)) + class TestParameterObject(unittest.TestCase): def test_signature_parameter_kinds(self): diff -r 1166b3321012 Python/compile.c --- a/Python/compile.c Thu Feb 13 12:48:54 2014 +0100 +++ b/Python/compile.c Fri Feb 14 14:15:37 2014 -0500 @@ -1533,8 +1533,17 @@ { if (annotation) { VISIT(c, expr, annotation); - if (PyList_Append(names, id)) - return -1; + PyObject *mangled = _Py_Mangle(c->u->u_private, id); + if (mangled) { + if (PyList_Append(names, mangled)) { + Py_DECREF(mangled); + return -1; + } + Py_DECREF(mangled); + } else { + if (PyList_Append(names, id)) + return -1; + } } return 0; }