PythonExtra/tests/basics/builtin_type.py
Jeff Epler 05b13fd292 py/objtype: Fix assertion failures in mp_obj_new_type by checking types.
Fixes assertion failures when the arguments to type() were not of valid
types, e.g., when making calls like:

    type("", (), 3)
    type("", 3, {})
2018-05-30 11:11:24 +10:00

32 lines
492 B
Python

# test builtin type
print(type(int))
try:
type()
except TypeError:
print('TypeError')
try:
type(1, 2)
except TypeError:
print('TypeError')
# second arg should be a tuple
try:
type('abc', None, None)
except TypeError:
print('TypeError')
# third arg should be a dict
try:
type('abc', (), None)
except TypeError:
print('TypeError')
# elements of second arg (the bases) should be types
try:
type('abc', (1,), {})
except TypeError:
print('TypeError')