PythonExtra/tests/basics/del_attr.py
Damien George b45c8c17f0 py/objtype: Check and prevent delete/store on a fixed locals map.
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.
2018-02-07 15:44:29 +11:00

40 lines
619 B
Python

class C:
def f():
pass
# 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")
# try to del an attribute of a built-in class
try:
del int.to_bytes
except (AttributeError, TypeError):
# uPy raises AttributeError, CPython raises TypeError
print('AttributeError/TypeError')