2015-08-30 11:32:26 +00:00
|
|
|
# tests for things that are not implemented, or have non-compliant behaviour
|
|
|
|
|
2017-03-11 00:16:26 +00:00
|
|
|
try:
|
2022-08-18 06:57:45 +00:00
|
|
|
import array
|
|
|
|
import struct
|
2017-03-11 00:16:26 +00:00
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-10 17:14:16 +00:00
|
|
|
raise SystemExit
|
2015-08-30 11:32:26 +00:00
|
|
|
|
2016-10-11 01:30:32 +00:00
|
|
|
# when super can't find self
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
exec("def f(): super()")
|
2016-10-11 01:30:32 +00:00
|
|
|
except SyntaxError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("SyntaxError")
|
2016-10-11 01:30:32 +00:00
|
|
|
|
2016-10-17 00:43:47 +00:00
|
|
|
# store to exception attribute is not allowed
|
|
|
|
try:
|
|
|
|
ValueError().x = 0
|
|
|
|
except AttributeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("AttributeError")
|
2016-10-17 00:43:47 +00:00
|
|
|
|
2015-08-30 11:32:26 +00:00
|
|
|
# array deletion not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
a = array.array("b", (1, 2, 3))
|
2015-08-30 11:32:26 +00:00
|
|
|
del a[1]
|
|
|
|
except TypeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("TypeError")
|
2015-08-30 11:32:26 +00:00
|
|
|
|
|
|
|
# slice with step!=1 not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
a = array.array("b", (1, 2, 3))
|
2015-08-30 11:32:26 +00:00
|
|
|
print(a[3:2:2])
|
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2015-08-30 11:32:26 +00:00
|
|
|
|
2016-10-17 00:43:47 +00:00
|
|
|
# containment, looking for integer not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
print(1 in array.array("B", b"12"))
|
2016-10-17 00:43:47 +00:00
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2016-10-17 00:43:47 +00:00
|
|
|
|
2023-03-08 03:10:02 +00:00
|
|
|
# uPy raises TypeError, should be ValueError
|
2015-08-30 11:32:26 +00:00
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
"%c" % b"\x01\x02"
|
2015-08-30 11:32:26 +00:00
|
|
|
except (TypeError, ValueError):
|
2020-03-23 02:26:08 +00:00
|
|
|
print("TypeError, ValueError")
|
2015-08-30 11:32:26 +00:00
|
|
|
|
|
|
|
# attributes/subscr not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("{a[0]}".format(a=[1, 2]))
|
2015-08-30 11:32:26 +00:00
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2015-09-01 14:35:31 +00:00
|
|
|
|
2015-09-03 22:06:18 +00:00
|
|
|
# str(...) with keywords not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
str(b"abc", encoding="utf8")
|
2015-09-03 22:06:18 +00:00
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2015-09-03 22:06:18 +00:00
|
|
|
|
2015-09-01 14:35:31 +00:00
|
|
|
# str.rsplit(None, n) not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
"a a a".rsplit(None, 1)
|
2015-09-01 14:35:31 +00:00
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2015-09-03 22:06:18 +00:00
|
|
|
|
2015-09-04 15:49:56 +00:00
|
|
|
# str.endswith(s, start) not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
"abc".endswith("c", 1)
|
2015-09-04 15:49:56 +00:00
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2015-09-04 15:49:56 +00:00
|
|
|
|
2016-10-17 00:43:47 +00:00
|
|
|
# str subscr with step!=1 not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("abc"[1:2:3])
|
2016-10-17 00:43:47 +00:00
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2016-10-17 00:43:47 +00:00
|
|
|
|
2015-09-03 22:06:18 +00:00
|
|
|
# bytes(...) with keywords not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
bytes("abc", encoding="utf8")
|
2015-09-03 22:06:18 +00:00
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2015-09-03 22:06:18 +00:00
|
|
|
|
|
|
|
# bytes subscr with step!=1 not implemented
|
|
|
|
try:
|
2020-03-23 02:26:08 +00:00
|
|
|
b"123"[0:3:2]
|
2015-09-03 22:06:18 +00:00
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2015-10-01 16:57:36 +00:00
|
|
|
|
2016-08-15 00:46:46 +00:00
|
|
|
# tuple load with step!=1 not implemented
|
|
|
|
try:
|
|
|
|
()[2:3:4]
|
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2016-08-15 00:46:46 +00:00
|
|
|
|
|
|
|
# list store with step!=1 not implemented
|
|
|
|
try:
|
|
|
|
[][2:3:4] = []
|
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2016-08-15 00:46:46 +00:00
|
|
|
|
|
|
|
# list delete with step!=1 not implemented
|
|
|
|
try:
|
|
|
|
del [][2:3:4]
|
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2016-10-07 01:57:25 +00:00
|
|
|
|
|
|
|
# struct pack with too many args, not checked by uPy
|
2022-08-18 06:57:45 +00:00
|
|
|
print(struct.pack("bb", 1, 2, 3))
|
2016-10-07 01:57:25 +00:00
|
|
|
|
|
|
|
# struct pack with too few args, not checked by uPy
|
2022-08-18 06:57:45 +00:00
|
|
|
print(struct.pack("bb", 1))
|
2016-12-21 06:51:42 +00:00
|
|
|
|
|
|
|
# array slice assignment with unsupported RHS
|
|
|
|
try:
|
|
|
|
bytearray(4)[0:1] = [1, 2]
|
|
|
|
except NotImplementedError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("NotImplementedError")
|
2017-01-19 12:38:53 +00:00
|
|
|
|
2023-02-02 00:51:48 +00:00
|
|
|
|
2017-01-19 12:38:53 +00:00
|
|
|
# can't assign attributes to a function
|
|
|
|
def f():
|
|
|
|
pass
|
2020-03-23 02:26:08 +00:00
|
|
|
|
|
|
|
|
2017-01-19 12:38:53 +00:00
|
|
|
try:
|
|
|
|
f.x = 1
|
|
|
|
except AttributeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("AttributeError")
|
2017-12-14 01:25:30 +00:00
|
|
|
|
|
|
|
# can't call a function type (ie make new instances of a function)
|
|
|
|
try:
|
|
|
|
type(f)()
|
|
|
|
except TypeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("TypeError")
|
2017-12-14 01:25:30 +00:00
|
|
|
|
2023-02-02 00:51:48 +00:00
|
|
|
|
2017-12-14 01:25:30 +00:00
|
|
|
# test when object explicitly listed at not-last position in parent tuple
|
|
|
|
# this is not compliant with CPython because of illegal MRO
|
|
|
|
class A:
|
|
|
|
def foo(self):
|
2020-03-23 02:26:08 +00:00
|
|
|
print("A.foo")
|
|
|
|
|
|
|
|
|
2017-12-14 01:25:30 +00:00
|
|
|
class B(object, A):
|
|
|
|
pass
|
2020-03-23 02:26:08 +00:00
|
|
|
|
|
|
|
|
2017-12-14 01:25:30 +00:00
|
|
|
B().foo()
|
py/objtype: Optimise instance get/set/del by skipping special accessors.
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%
2018-05-25 07:09:54 +00:00
|
|
|
|
2023-02-02 00:51:48 +00:00
|
|
|
|
py/objtype: Optimise instance get/set/del by skipping special accessors.
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%
2018-05-25 07:09:54 +00:00
|
|
|
# can't assign property (or other special accessors) to already-subclassed class
|
|
|
|
class A:
|
|
|
|
pass
|
2020-03-23 02:26:08 +00:00
|
|
|
|
|
|
|
|
py/objtype: Optimise instance get/set/del by skipping special accessors.
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%
2018-05-25 07:09:54 +00:00
|
|
|
class B(A):
|
|
|
|
pass
|
2020-03-23 02:26:08 +00:00
|
|
|
|
|
|
|
|
py/objtype: Optimise instance get/set/del by skipping special accessors.
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%
2018-05-25 07:09:54 +00:00
|
|
|
try:
|
|
|
|
A.bar = property()
|
|
|
|
except AttributeError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("AttributeError")
|