Skip to content

Commit

Permalink
Merge 622c45a into c8b0557
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleech committed Dec 4, 2020
2 parents c8b0557 + 622c45a commit 76d5e11
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions ports/unix/variants/coverage/mpconfigvariant.h
Expand Up @@ -63,6 +63,7 @@
#define MICROPY_PY_UCRYPTOLIB (1)
#define MICROPY_PY_UCRYPTOLIB_CTR (1)
#define MICROPY_PY_MICROPYTHON_HEAP_LOCKED (1)
#define MICROPY_PY_CLASS_ORDERED_LOCALS (1)

// use vfs's functions for import stat and builtin open
#define mp_import_stat mp_vfs_import_stat
Expand Down
5 changes: 5 additions & 0 deletions py/modbuiltins.c
Expand Up @@ -52,6 +52,11 @@ STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args)
// set the new classes __locals__ object
mp_obj_dict_t *old_locals = mp_locals_get();
mp_obj_t class_locals = mp_obj_new_dict(0);
#if MICROPY_PY_CLASS_ORDERED_LOCALS
// keep the locals ordered
mp_obj_dict_t *dict = MP_OBJ_TO_PTR(class_locals);
dict->map.is_ordered = 1;
#endif
mp_locals_set(MP_OBJ_TO_PTR(class_locals));

// call the class code
Expand Down
26 changes: 26 additions & 0 deletions tests/basics/class_dict_order.py
@@ -0,0 +1,26 @@
# test __dict__ attribute ordering of a class

if not hasattr(int, "__dict__"):
print("SKIP")
raise SystemExit

from collections import OrderedDict

# dict of a user class
class Foo:
abcd = 1
efgh = 2
ijkl = 3

# dict of a user class
class Foo2:
ijkl = 3
abcd = 1
efgh = 2

print([k for k in Foo.__dict__.keys() if not k.startswith('_')])
print([k for k in Foo2.__dict__.keys() if not k.startswith('_')])


Foo3 = type('Foo3', (object,), OrderedDict(abcd=1, efgh=2, ijkl=3))
print([k for k in Foo3.__dict__.keys() if not k.startswith('_')])
1 change: 1 addition & 0 deletions tests/run-tests
Expand Up @@ -374,6 +374,7 @@ def run_tests(pyb, tests, args, result_dir):

if not has_coverage:
skip_tests.add('cmdline/cmd_parsetree.py')
skip_tests.add('basics/class_dict_order.py')

# Some tests shouldn't be run on a PC
if args.target == 'unix':
Expand Down

0 comments on commit 76d5e11

Please sign in to comment.