mirror of
https://github.com/micropython/micropython.git
synced 2025-09-07 02:10:52 +02:00
Note that the check for elem!=NULL is removed for the MP_MAP_LOOKUP_ADD_IF_NOT_FOUND case because mp_map_lookup will always return non-NULL for such a case.
26 lines
436 B
Python
26 lines
436 B
Python
class A:
|
|
|
|
var = 132
|
|
|
|
def __init__(self):
|
|
self.var2 = 34
|
|
|
|
|
|
a = A()
|
|
setattr(a, "var", 123)
|
|
setattr(a, "var2", 56)
|
|
print(a.var)
|
|
print(a.var2)
|
|
|
|
try:
|
|
setattr(a, b'var3', 1)
|
|
except TypeError:
|
|
print('TypeError')
|
|
|
|
# try setattr on a built-in function
|
|
try:
|
|
setattr(int, 'to_bytes', 1)
|
|
except (AttributeError, TypeError):
|
|
# uPy raises AttributeError, CPython raises TypeError
|
|
print('AttributeError/TypeError')
|