Skip to content

Commit 3deeabe

Browse files
trwboxdpgeorge
authored andcommitted
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>
1 parent 2962e24 commit 3deeabe

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
categories: Core,Classes
3+
description: Private Class Members name mangling is not implemented
4+
cause: The MicroPython compiler does not implement name mangling for private class members.
5+
workaround: Avoid using or having a collision with global names, by adding a unique prefix to the private class member name manually.
6+
"""
7+
8+
9+
def __print_string(string):
10+
print(string)
11+
12+
13+
class Foo:
14+
def __init__(self, string):
15+
self.string = string
16+
17+
def do_print(self):
18+
__print_string(self.string)
19+
20+
21+
example_string = "Example String to print."
22+
23+
class_item = Foo(example_string)
24+
print(class_item.string)
25+
26+
class_item.do_print()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy