diff options
author | Trent Warlaven <trwbox@gmail.com> | 2023-08-06 12:03:47 -0500 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-02-21 11:42:35 +1100 |
commit | 3deeabe6e87d893196227b41ca997d78783ab14c (patch) | |
tree | 34cc437e25ebf9a650bc93ed858b9fbf00cb48aa | |
parent | 2962e24167a7416d4caf8d25f463e67b46c3a40a (diff) |
tests/cpydiff: Add new CPy diff test for class name mangling.
Adds new tests/documentation for missing name mangling for private class
members.
Signed-off-by: Trent Warlaven <trwbox@gmail.com>
-rw-r--r-- | tests/cpydiff/core_class_name_mangling.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/cpydiff/core_class_name_mangling.py b/tests/cpydiff/core_class_name_mangling.py new file mode 100644 index 000000000..39153209d --- /dev/null +++ b/tests/cpydiff/core_class_name_mangling.py @@ -0,0 +1,26 @@ +""" +categories: Core,Classes +description: Private Class Members name mangling is not implemented +cause: The MicroPython compiler does not implement name mangling for private class members. +workaround: Avoid using or having a collision with global names, by adding a unique prefix to the private class member name manually. +""" + + +def __print_string(string): + print(string) + + +class Foo: + def __init__(self, string): + self.string = string + + def do_print(self): + __print_string(self.string) + + +example_string = "Example String to print." + +class_item = Foo(example_string) +print(class_item.string) + +class_item.do_print() |