aboutsummaryrefslogtreecommitdiff
path: root/tests/misc/non_compliant.py
AgeCommit message (Collapse)Author
2020-03-30tests: Format all Python code with black, except tests in basics subdir.David Lechner
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
2019-10-22tests: Rename "array" module to "uarray".Damien George
2018-06-08py/objtype: Optimise instance get/set/del by skipping special accessors.Damien George
This patch is a code optimisation, trading text bytes for speed. On pyboard it's an increase of 0.06% in code size for a gain (in pystone performance) of roughly 6.5%. The patch optimises load/store/delete of attributes in user defined classes by not looking up special accessors (@property, __get__, __delete__, __set__, __setattr__ and __getattr_) if they are guaranteed not to exist in the class. Currently, if you do my_obj.foo() then the runtime has to do a few checks to see if foo is a property or has __get__, and if so delegate the call. And for stores things like my_obj.foo = 1 has to first check if foo is a property or has __set__ defined on it. Doing all those checks each and every time the attribute is accessed has a performance penalty. This patch eliminates all those checks for cases when it's guaranteed that the checks will always fail, ie no attributes are properties nor have any special accessor methods defined on them. To make this guarantee it checks all attributes of a user-defined class when it is first created. If any of the attributes of the user class are properties or have special accessors, or any of the base classes of the user class have them, then it sets a flag in the class to indicate that special accessors must be checked for. Then in the load/store/delete code it checks this flag to see if it can take the shortcut and optimise the lookup. It's an optimisation that's pretty widely applicable because it improves lookup performance for all methods of user defined classes, and stores of attributes, at least for those that don't have special accessors. And, it allows to enable descriptors with minimal additional runtime overhead if they are not used for a particular user class. There is one restriction on dynamic class creation that has been introduced by this patch: a user-defined class cannot go from zero special accessors to one special accessor (or more) after that class has been subclassed. If the script attempts this an AttributeError is raised (see addition to tests/misc/non_compliant.py for an example of this case). The cost in code space bytes for the optimisation in this patch is: unix x64: +528 unix nanbox: +508 stm32: +192 cc3200: +200 esp8266: +332 esp32: +244 Performance tests that were done: - on unix x86-64, pystone improved by about 5% - on pyboard, pystone improved by about 6.5%, from 1683 up to 1794 - on pyboard, bm_chaos (from CPython benchmark suite) improved by about 5% - on esp32, pystone improved by about 30% (but there are caching effects) - on esp32, bm_chaos improved by about 11%
2017-12-14tests: Add tests to improve coverage of py/objtype.c.Damien George
2017-10-03py/objset: Check that RHS of a binary op is a set/frozenset.Damien George
CPython docs explicitly state that the RHS of a set/frozenset binary op must be a set to prevent user errors. It also preserves commutativity of the ops, eg: "abc" & set() is a TypeError, and so should be set() & "abc". This change actually decreases unix (x64) code by 160 bytes; it increases stm32 by 4 bytes and esp8266 by 28 bytes (but previous patch already introduced a much large saving).
2017-06-10tests: Convert remaining "sys.exit()" to "raise SystemExit".Paul Sokolovsky
2017-03-11tests/misc/: Make few tests skippable.Paul Sokolovsky
2017-01-19tests/misc/non_compliant: Add test for inability to assign func attrs.Damien George
2016-12-21tests: Add tests to improve coverage of objarray.c.Rami Ali
2016-10-17tests: Improve coverage of array, range, dict, slice, exc, unicode.Damien George
2016-10-11tests: Improve test coverage of py/compile.c.Damien George
2016-10-07tests: Improve coverage of struct with test for non-compliant behaviour.Damien George
2016-08-15tests/misc/non_compliant: Add tests to improve coverage testing.Damien George
2016-02-03py/mpz: Complete implementation of mpz_{and,or,xor} for negative args.Doug Currie
For these 3 bitwise operations there are now fast functions for positive-only arguments, and general functions for arbitrary sign arguments (the fast functions are the existing implementation). By default the fast functions are not used (to save space) and instead the general functions are used for all operations. Enable MICROPY_OPT_MPZ_BITWISE to use the fast functions for positive arguments.
2016-01-07py/parse: Improve constant folding to operate on small and big ints.Damien George
Constant folding in the parser can now operate on big ints, whatever their representation. This is now possible because the parser can create parse nodes holding arbitrary objects. For the case of small ints the folding is still efficient in RAM because the folded small int is stored inplace in the parse node. Adds 48 bytes to code size on Thumb2 architecture. Helps reduce heap usage because more constants can be computed at compile time, leading to a smaller parse tree, and most importantly means that the constants don't have to be computed at runtime (perhaps more than once). Parser will now be a little slower when folding due to calls to runtime to do the arithmetic.
2015-10-01py/mpz: Raise NotImplError instead of failing assertion.Damien George
2015-09-04py/objstr: For str.endswith(s, start) raise NotImpl instead of assert.Damien George
2015-09-03tests: Add tests to improve coverage of objstr.c.Damien George
2015-09-01py/objstr: Make str.rsplit(None,n) raise NotImpl instead of assert(0).Damien George
2015-08-30tests: Add tests for non-compliant behaviour.Damien George
These tests are intended to improve coverage and provide a record of behaviour that's either not implemented or non-compliant to CPython.