mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 05:00:26 +01:00
py: Remove DELETE_SUBSCR opcode, combine with STORE_SUBSCR.
This makes the runtime and object APIs more consistent. mp_store_subscr functionality now moved into objects (ie list and dict store_item).
This commit is contained in:
28
tests/basics/del-attr.py
Normal file
28
tests/basics/del-attr.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# del a class attribute
|
||||
|
||||
del C.f
|
||||
try:
|
||||
print(C.x)
|
||||
except AttributeError:
|
||||
print("AttributeError")
|
||||
try:
|
||||
del C.f
|
||||
except AttributeError:
|
||||
print("AttributeError")
|
||||
|
||||
# del an instance attribute
|
||||
|
||||
c = C()
|
||||
|
||||
c.x = 1
|
||||
print(c.x)
|
||||
|
||||
del c.x
|
||||
try:
|
||||
print(c.x)
|
||||
except AttributeError:
|
||||
print("AttributeError")
|
||||
try:
|
||||
del c.x
|
||||
except AttributeError:
|
||||
print("AttributeError")
|
||||
18
tests/basics/del-name.py
Normal file
18
tests/basics/del-name.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# del global
|
||||
|
||||
x = 1
|
||||
print(x)
|
||||
del x
|
||||
try:
|
||||
print(x)
|
||||
except NameError:
|
||||
print("NameError")
|
||||
try:
|
||||
del x
|
||||
except: # NameError:
|
||||
# FIXME uPy returns KeyError for this
|
||||
print("NameError")
|
||||
|
||||
class C:
|
||||
def f():
|
||||
pass
|
||||
13
tests/basics/del-subscr.py
Normal file
13
tests/basics/del-subscr.py
Normal file
@@ -0,0 +1,13 @@
|
||||
l = [1, 2, 3]
|
||||
print(l)
|
||||
del l[0]
|
||||
print(l)
|
||||
del l[-1]
|
||||
print(l)
|
||||
|
||||
d = {1:2, 3:4, 5:6}
|
||||
del d[1]
|
||||
del d[3]
|
||||
print(d)
|
||||
del d[5]
|
||||
print(d)
|
||||
Reference in New Issue
Block a user