diff options
author | stijn <stijn@ignitron.net> | 2024-08-21 16:22:01 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-10-07 11:37:52 +1100 |
commit | 338df1ae357eefe987df4429b88d3094f9c7b8c2 (patch) | |
tree | f2d3d9197a8d14c2be602a820a38126e77781c32 /tests/basics/subclass_native_init.py | |
parent | 548f88d2bd254f1328014a303f8bf602a0646421 (diff) | |
download | micropython-338df1ae357eefe987df4429b88d3094f9c7b8c2.tar.gz micropython-338df1ae357eefe987df4429b88d3094f9c7b8c2.zip |
py/objtype: Allow passing keyword arguments to native base __init__.
Allowing passing keyword arguments to a native base's __init__, i.e.
`make_new` in the C code. Previously only positional arguments were
allowed.
The main trade-off in this commit is that every call to the native base's
`make_new` is now going to be preceded by a call to
`mp_map_init_fixed_table` even though most of what that does is unused and
instead it merely serves as a way to pass the number of keyword arguments.
Fixes issue #15465.
Signed-off-by: stijn <stijn@ignitron.net>
Diffstat (limited to 'tests/basics/subclass_native_init.py')
-rw-r--r-- | tests/basics/subclass_native_init.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/basics/subclass_native_init.py b/tests/basics/subclass_native_init.py index 38d2f23ac3..64167fa037 100644 --- a/tests/basics/subclass_native_init.py +++ b/tests/basics/subclass_native_init.py @@ -6,6 +6,35 @@ class L(list): super().__init__([a, b]) print(L(2, 3)) +# with keyword arguments, with star arguments and without because those use different C calls +class D(dict): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) +print(D()) +print(D([('a', 1)])) +print(D([('a', 1)], a=2, b=3)) +print(D(a=2, b=3)) + +class D(dict): + def __init__(self): + super().__init__() +print(D()) + +class D(dict): + def __init__(self): + super().__init__([]) +print(D()) + +class D(dict): + def __init__(self): + super().__init__(a=1) +print(D()) + +class D(dict): + def __init__(self): + super().__init__([], a=1) +print(D()) + # inherits implicitly from object class A: def __init__(self): |