Drop support for Python classic classes

There were only needed to support Python < 2.2, and we now require at
least Python 2.6.

 Conflicts:
	.travis.yml
	Examples/test-suite/python/autodoc_runme.py
	Source/Modules/python.cxx

This is a cherry-pick and merge from patch in #1261
This commit is contained in:
Olly Betts 2018-05-19 11:47:23 +12:00 committed by William S Fulton
commit 728b8955bd
20 changed files with 96 additions and 241 deletions

View file

@ -10,9 +10,6 @@ def check(got, expected, expected_builtin=None, skip=False):
expect = expected_builtin
comment_verifier.check(got, expect)
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def is_fastproxy():
fastproxy = True
try:
@ -21,11 +18,6 @@ def is_fastproxy():
fastproxy = False
return fastproxy
if not is_new_style_class(A):
# Missing static methods make this hard to test... skip if -classic is
# used!
sys.exit(0)
if is_fastproxy():
# Detect when -fastproxy is specified and skip test as it changes the function names making it
# hard to test... skip until the number of options are reduced in SWIG-3.1 and autodoc is improved

View file

@ -2,17 +2,9 @@
from cpp_static import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
if is_new_style_class(StaticFunctionTest):
StaticFunctionTest.static_func()
StaticFunctionTest.static_func_2(1)
StaticFunctionTest.static_func_3(1, 2)
else:
StaticFunctionTest().static_func()
StaticFunctionTest().static_func_2(1)
StaticFunctionTest().static_func_3(1, 2)
StaticFunctionTest.static_func()
StaticFunctionTest.static_func_2(1)
StaticFunctionTest.static_func_3(1, 2)
if is_python_builtin():
if not StaticMemberTest.static_int == 99: raise RuntimeError("static_int not 99")

View file

@ -2,10 +2,6 @@
# the use of __main__ and the run function
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def run(module_name):
default_args = __import__(module_name)
ec = default_args.EnumClass()
@ -101,10 +97,7 @@ def run(module_name):
if error:
raise RuntimeError("Foo::meth ignore is not working")
if is_new_style_class(default_args.Klass):
Klass_inc = default_args.Klass.inc
else:
Klass_inc = default_args.Klass_inc
Klass_inc = default_args.Klass.inc
if Klass_inc(100, default_args.Klass(22)).val != 122:
raise RuntimeError("Klass::inc failed")

View file

@ -1,10 +1,6 @@
import director_abstract
def is_new_style_class(cls):
return hasattr(cls, "__class__")
class MyFoo(director_abstract.Foo):
def __init__(self):
@ -44,20 +40,12 @@ me1 = MyExample1()
if director_abstract.Example1_get_color(me1, 1, 2, 3) != 1:
raise RuntimeError
if is_new_style_class(MyExample2):
MyExample2_static = MyExample2
else:
MyExample2_static = MyExample2(0, 0)
me2 = MyExample2(1, 2)
if MyExample2_static.get_color(me2, 1, 2, 3) != 2:
if MyExample2.get_color(me2, 1, 2, 3) != 2:
raise RuntimeError
if is_new_style_class(MyExample3):
MyExample3_static = MyExample3
else:
MyExample3_static = MyExample3()
me3 = MyExample3()
if MyExample3_static.get_color(me3, 1, 2, 3) != 3:
if MyExample3.get_color(me3, 1, 2, 3) != 3:
raise RuntimeError
error = 1

View file

@ -1,9 +1,6 @@
from global_namespace import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
k1 = Klass1()
k2 = Klass2()
k3 = Klass3()
@ -12,12 +9,8 @@ k5 = Klass5()
k6 = Klass6()
k7 = Klass7()
if is_new_style_class(KlassMethods):
KlassMethods_static = KlassMethods
else:
KlassMethods_static = KlassMethods()
KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
k1 = getKlass1A()
k2 = getKlass2A()
@ -27,8 +20,8 @@ k5 = getKlass5A()
k6 = getKlass6A()
k7 = getKlass7A()
KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
k1 = getKlass1B()
k2 = getKlass2B()
@ -38,21 +31,11 @@ k5 = getKlass5B()
k6 = getKlass6B()
k7 = getKlass7B()
KlassMethods_static.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods_static.methodB(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodA(k1, k2, k3, k4, k5, k6, k7)
KlassMethods.methodB(k1, k2, k3, k4, k5, k6, k7)
if is_new_style_class(XYZMethods):
XYZMethods_static = XYZMethods
else:
XYZMethods_static = XYZMethods()
XYZMethods_static.methodA(
XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
XYZMethods_static.methodB(
XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
XYZMethods.methodA(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
XYZMethods.methodB(XYZ1(), XYZ2(), XYZ3(), XYZ4(), XYZ5(), XYZ6(), XYZ7())
if is_new_style_class(TheEnumMethods):
TheEnumMethods_static = TheEnumMethods
else:
TheEnumMethods_static = TheEnumMethods()
TheEnumMethods_static.methodA(theenum1, theenum2, theenum3)
TheEnumMethods_static.methodA(theenum1, theenum2, theenum3)
TheEnumMethods.methodA(theenum1, theenum2, theenum3)
TheEnumMethods.methodA(theenum1, theenum2, theenum3)

View file

@ -6,9 +6,6 @@ def check(a, b):
raise RuntimeError(str(a) + " does not equal " + str(b))
def is_new_style_class(cls):
return hasattr(cls, "__class__")
#### Class ####
# No implicit conversion
@ -45,17 +42,13 @@ check(2, A_int(1.0).get())
check(3, A_int(B()).get())
check(4, A_int("hello").get())
if is_new_style_class(A_int):
A_int_static = A_int
else:
A_int_static = A_int(0)
check(1, A_int_static.sget(1))
check(2, A_int_static.sget(1.0))
check(3, A_int_static.sget(B()))
check(1, A_int.sget(1))
check(2, A_int.sget(1.0))
check(3, A_int.sget(B()))
# explicit constructor:
try:
check(4, A_int_static.sget("hello"))
check(4, A_int.sget("hello"))
raise RuntimeError
except TypeError:
pass

View file

@ -1,10 +1,6 @@
from li_boost_shared_ptr_bits import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def check(nd):
nd.i = 200
i = nd.i
@ -35,7 +31,4 @@ if sum != 66:
raise "sum is wrong"
################################
if is_new_style_class(HiddenDestructor):
p = HiddenDestructor.create()
else:
p = HiddenDestructor_create()
p = HiddenDestructor.create()

View file

@ -1,9 +1,5 @@
from namespace_class import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
try:
p = Private1()
error = 1
@ -22,10 +18,7 @@ except:
if (error):
raise RuntimeError, "Private2 is private"
if is_new_style_class(EulerT3D):
EulerT3D.toFrame(1, 1, 1)
else:
EulerT3D().toFrame(1, 1, 1)
EulerT3D.toFrame(1, 1, 1)
b = BooT_i()
b = BooT_H()
@ -40,7 +33,6 @@ f.moo(1)
f = FooT_H()
f.foo(Hi)
if is_new_style_class(FooT_H):
f_type = str(type(f))
if f_type.find("'namespace_class.FooT_H'") == -1:
raise RuntimeError("Incorrect type: " + f_type)
f_type = str(type(f))
if f_type.find("'namespace_class.FooT_H'") == -1:
raise RuntimeError("Incorrect type: " + f_type)

View file

@ -1,9 +1,5 @@
from overload_template_fast import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
f = foo()
a = maximum(3, 4)
@ -145,9 +141,6 @@ if (nsoverload() != 1050):
raise RuntimeError, ("nsoverload(const char *)")
if is_new_style_class(A):
A.foo(1)
else:
A_foo(1)
A.foo(1)
b = B()
b.foo(1)

View file

@ -1,19 +1,13 @@
from python_append import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
# test not relevant for -builtin
if is_python_builtin():
exit(0)
t = Test()
t.funk()
if is_new_style_class(Test):
t.static_func()
else:
Test_static_func()
t.static_func()
if grabpath() != os.path.dirname(mypath):
raise RuntimeError("grabpath failed")

View file

@ -9,7 +9,7 @@ def check(got, expected):
raise RuntimeError("\n" + "Expected: " + str(expected_list) + "\n" + "Got : " + str(got_list))
# When getting docstrings, use inspect.getdoc(x) instead of x.__doc__ otherwise the different options
# such as -O, -builtin, -classic produce different initial indentation.
# such as -O and -builtin may produce different initial indentation.
check(inspect.getdoc(DocStrings.docstring1),
" line 1\n"

View file

@ -3,17 +3,11 @@ import python_pickle
import pickle
import sys
def is_new_style_class(cls):
return hasattr(cls, "__class__")
def check(p):
msg = p.msg
if msg != "hi there":
raise RuntimeError("Bad, got: " + msg)
if not is_new_style_class(python_pickle.PickleMe):
sys.exit(0)
python_pickle.cvar.debug = False
p = python_pickle.PickleMe("hi there")

View file

@ -6,9 +6,6 @@ def check_unorderable_types(exception):
# raise RuntimeError("A TypeError 'unorderable types' exception was expected"), None, sys.exc_info()[2]
pass # Exception message seems to vary from one version of Python to another
def is_new_style_class(cls):
return hasattr(cls, "__class__")
base1 = python_richcompare.BaseClass(1)
base2 = python_richcompare.BaseClass(2)
base3 = python_richcompare.BaseClass(3)
@ -103,39 +100,37 @@ if not (a2 <= b2):
# Check inequalities to other objects
#-------------------------------------------------------------------------------
if is_new_style_class(python_richcompare.BaseClass):
# Skip testing -classic option
if sys.version_info[0:2] < (3, 0):
if (base1 < 42):
raise RuntimeError("Comparing class to incompatible type, < returned True")
if (base1 <= 42):
raise RuntimeError("Comparing class to incompatible type, <= returned True")
if not (base1 > 42):
raise RuntimeError("Comparing class to incompatible type, > returned False")
if not (base1 >= 42):
raise RuntimeError("Comparing class to incompatible type, >= returned False")
else:
# Python 3 throws: TypeError: unorderable types
try:
res = base1 < 42
raise RuntimeError("Failed to throw")
except TypeError,e:
check_unorderable_types(e)
try:
res = base1 <= 42
raise RuntimeError("Failed to throw")
except TypeError,e:
check_unorderable_types(e)
try:
res = base1 > 42
raise RuntimeError("Failed to throw")
except TypeError,e:
check_unorderable_types(e)
try:
res = base1 >= 42
raise RuntimeError("Failed to throw")
except TypeError,e:
check_unorderable_types(e)
if sys.version_info[0:2] < (3, 0):
if (base1 < 42):
raise RuntimeError("Comparing class to incompatible type, < returned True")
if (base1 <= 42):
raise RuntimeError("Comparing class to incompatible type, <= returned True")
if not (base1 > 42):
raise RuntimeError("Comparing class to incompatible type, > returned False")
if not (base1 >= 42):
raise RuntimeError("Comparing class to incompatible type, >= returned False")
else:
# Python 3 throws: TypeError: unorderable types
try:
res = base1 < 42
raise RuntimeError("Failed to throw")
except TypeError,e:
check_unorderable_types(e)
try:
res = base1 <= 42
raise RuntimeError("Failed to throw")
except TypeError,e:
check_unorderable_types(e)
try:
res = base1 > 42
raise RuntimeError("Failed to throw")
except TypeError,e:
check_unorderable_types(e)
try:
res = base1 >= 42
raise RuntimeError("Failed to throw")
except TypeError,e:
check_unorderable_types(e)
# Check inequalities used for ordering
#-------------------------------------------------------------------------

View file

@ -1,9 +1,6 @@
from smart_pointer_member import *
def is_new_style_class(cls):
return hasattr(cls, "__class__")
f = Foo()
f.y = 1
@ -24,6 +21,5 @@ if b.x != f.x:
if b.z != f.z:
raise RuntimeError
if is_new_style_class(Bar): # feature not supported in old style classes
if Foo.z == Bar.z:
raise RuntimeError
if Foo.z == Bar.z:
raise RuntimeError