78d702c300
This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS) which, when enabled, allows to override all names within the builtins module. A builtins override dict is created the first time the user assigns to a name in the builtins model, and then that dict is searched first on subsequent lookups. Note that this implementation doesn't allow deleting of names. This patch also does some refactoring of builtins code, creating the modbuiltins.c file. Addresses issue #959.
14 lines
244 B
Python
14 lines
244 B
Python
# test overriding builtins
|
|
|
|
import builtins
|
|
|
|
# override generic builtin
|
|
builtins.abs = lambda x: x + 1
|
|
print(abs(1))
|
|
|
|
# __build_class__ is handled in a special way
|
|
builtins.__build_class__ = lambda x, y: ('class', y)
|
|
class A:
|
|
pass
|
|
print(A)
|