Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: py3.6 Changeset: r95350:c761510af951 Date: 2018-11-20 21:33 +0100 http://bitbucket.org/pypy/pypy/changeset/c761510af951/
Log: (Ryan Hileman, alcarithemad) fix problem with variable annotations and ternary expressions fixes issue 2916 diff --git a/pypy/interpreter/astcompiler/astbuilder.py b/pypy/interpreter/astcompiler/astbuilder.py --- a/pypy/interpreter/astcompiler/astbuilder.py +++ b/pypy/interpreter/astcompiler/astbuilder.py @@ -791,7 +791,7 @@ annotation = self.handle_expr(second.get_child(1)) value_expr = None if second.num_children() == 4: - value_expr = self.handle_testlist(second.get_child(-1)) + value_expr = self.handle_expr(second.get_child(-1)) return ast.AnnAssign(target_expr, annotation, value_expr, simple, stmt.get_lineno(), stmt.get_column()) else: # Normal assignment. diff --git a/pypy/interpreter/test/test_annotations.py b/pypy/interpreter/test/test_annotations.py --- a/pypy/interpreter/test/test_annotations.py +++ b/pypy/interpreter/test/test_annotations.py @@ -99,6 +99,14 @@ assert False ''' + def test_ternary_expression_bug(self): + """ + class C: + var: bool = True if False else False + assert var is False + assert C.__annotations__ == {"var": bool} + """ + def test_reassigned___annotations__(self): ''' class C: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit