From b1533c43669c037d04c87d1756355cdc8edd5e0a Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 6 Jun 2016 17:28:32 +0100 Subject: py/parse: Treat constants that start with underscore as private. Assignments of the form "_id = const(value)" are treated as private (following a similar CPython convention) and code is no longer emitted for the assignment to a global variable. See issue #2111. --- tests/micropython/const.py | 12 ++++++++++++ tests/micropython/const.py.exp | 3 +++ 2 files changed, 15 insertions(+) (limited to 'tests/micropython') diff --git a/tests/micropython/const.py b/tests/micropython/const.py index 457365c50..09717fd14 100644 --- a/tests/micropython/const.py +++ b/tests/micropython/const.py @@ -9,3 +9,15 @@ def f(): print(X, Y + 1) f() + +_X = const(12) +_Y = const(_X + 34) + +print(_X, _Y) + +class A: + Z = const(1) + _Z = const(2) + print(Z, _Z) + +print(hasattr(A, 'Z'), hasattr(A, '_Z')) diff --git a/tests/micropython/const.py.exp b/tests/micropython/const.py.exp index c447aaf8c..ece6a5cb2 100644 --- a/tests/micropython/const.py.exp +++ b/tests/micropython/const.py.exp @@ -1,2 +1,5 @@ 123 580 123 580 +12 46 +1 2 +True False -- cgit v1.2.3