Skip to content

Commit 21b683f

Browse files
committed
Upgrade syntax to Python 3
1 parent 5310ccb commit 21b683f

23 files changed

+147
-154
lines changed

bench/py_functioncalls.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ def empty_call():
66
pass
77

88
#- group: empty-inst ---------------------------------------------------------
9-
class EmptyCall(object):
9+
class EmptyCall:
1010
def empty_call(self):
1111
pass
1212

1313

1414
#- group: builtin-args-free --------------------------------------------------
15-
class Value(object):
15+
class Value:
1616
def __init__(self):
1717
self.m_int = 42
1818

@@ -26,7 +26,7 @@ def take_a_struct(val):
2626
pass
2727

2828
#- group: builtin-args-inst --------------------------------------------------
29-
class TakeAValue(object):
29+
class TakeAValue:
3030
def take_an_int(self, val):
3131
pass
3232

@@ -45,12 +45,12 @@ def do_work(val):
4545
return math.atan(val)
4646

4747
#- group: do_work-inst -------------------------------------------------------
48-
class DoWork(object):
48+
class DoWork:
4949
def do_work(self, val):
5050
return math.atan(val)
5151

5252

5353
#- group: overload-inst ------------------------------------------------------
54-
class OverloadedCall(object):
54+
class OverloadedCall:
5555
def add_it(self, *args):
5656
return 3.1415 + sum(args)

bench/support.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import py, sys, subprocess
32

43
currpath = py.path.local(__file__).dirpath()
@@ -11,4 +10,4 @@ def setup_make(targetname):
1110
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
1211
stdout, _ = popen.communicate()
1312
if popen.returncode:
14-
raise OSError("'make' failed:\n%s" % (stdout,))
13+
raise OSError("'make' failed:\n{}".format(stdout))

python/cppyy/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def __ne__(self, other):
152152

153153
# std::make_shared/unique create needless templates: rely on Python's introspection
154154
# instead. This also allows Python derived classes to be handled correctly.
155-
class py_make_smartptr(object):
155+
class py_make_smartptr:
156156
__slots__ = ['cls', 'ptrcls']
157157
def __init__(self, cls, ptrcls):
158158
self.cls = cls
@@ -164,7 +164,7 @@ def __call__(self, *args):
164164
obj = self.cls(*args)
165165
return self.ptrcls[self.cls](obj) # C++ takes ownership
166166

167-
class make_smartptr(object):
167+
class make_smartptr:
168168
__slots__ = ['ptrcls', 'maker']
169169
def __init__(self, ptrcls, maker):
170170
self.ptrcls = ptrcls
@@ -187,7 +187,7 @@ def __getitem__(self, cls):
187187

188188

189189
#--- interface to Cling ------------------------------------------------------
190-
class _stderr_capture(object):
190+
class _stderr_capture:
191191
def __init__(self):
192192
self._capture = not gbl.Cpp.IsDebugOutputEnabled()
193193
self.err = ""
@@ -240,7 +240,7 @@ def load_library(name):
240240
CppInterOp = gbl.Cpp
241241
result = CppInterOp.LoadLibrary(name)
242242
if result == False:
243-
raise RuntimeError('Could not load library "%s": %s' % (name, err.err))
243+
raise RuntimeError('Could not load library "{}": {}'.format(name, err.err))
244244

245245
return True
246246

@@ -249,7 +249,7 @@ def include(header):
249249
with _stderr_capture() as err:
250250
errcode = gbl.Cpp.Declare('#include "%s"' % header)
251251
if not errcode == 0:
252-
raise ImportError('Failed to load header file "%s"%s' % (header, err.err))
252+
raise ImportError('Failed to load header file "{}"{}'.format(header, err.err))
253253
return True
254254

255255
def c_include(header):
@@ -259,7 +259,7 @@ def c_include(header):
259259
#include "%s"
260260
}""" % header)
261261
if not errcode == 0:
262-
raise ImportError('Failed to load header file "%s"%s' % (header, err.err))
262+
raise ImportError('Failed to load header file "{}"{}'.format(header, err.err))
263263
return True
264264

265265
def add_include_path(path):
@@ -389,7 +389,7 @@ def sizeof(tt):
389389
try:
390390
sz = ctypes.sizeof(tt)
391391
except TypeError:
392-
sz = gbl.Cpp.Evaluate("sizeof(%s)" % (_get_name(tt),))
392+
sz = gbl.Cpp.Evaluate("sizeof({})".format(_get_name(tt)))
393393
_sizes[tt] = sz
394394
return sz
395395

python/cppyy/_cpython_cppyy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def ismethod(object):
5454

5555

5656
### template support ---------------------------------------------------------
57-
class Template(object): # expected/used by ProxyWrappers.cxx in CPyCppyy
57+
class Template: # expected/used by ProxyWrappers.cxx in CPyCppyy
5858
stl_sequence_types = ['std::vector', 'std::list', 'std::set', 'std::deque']
5959
stl_unrolled_types = ['std::pair']
6060
stl_fixed_size_types = ['std::array']
@@ -67,7 +67,7 @@ def __init__(self, name, scope):
6767
self.__scope__ = scope
6868

6969
def __repr__(self):
70-
return "<cppyy.Template '%s' object at %s>" % (self.__name__, hex(id(self)))
70+
return "<cppyy.Template '{}' object at {}>".format(self.__name__, hex(id(self)))
7171

7272
def __getitem__(self, *args):
7373
# multi-argument to [] becomes a single tuple argument
@@ -177,7 +177,7 @@ def add_default_paths():
177177
f = line.strip()
178178
if (os.path.exists(f)):
179179
libCppInterOp.AddSearchPath(f)
180-
except IOError:
180+
except OSError:
181181
pass
182182
add_default_paths()
183183
del add_default_paths

python/cppyy/_pythonization.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ def set_ownership_policy(match_class, match_method, python_owns_result):
5959
# NB: Ideally, we'd use the version commented out below, but for now, we
6060
# make do with the hackier version here.
6161
def rename_attribute(match_class, orig_attribute, new_attribute, keep_orig=False):
62-
class attribute_pythonizor(object):
63-
class getter(object):
62+
class attribute_pythonizor:
63+
class getter:
6464
def __init__(self, attr):
6565
self.attr = attr
6666
def __call__(self, obj):
6767
return getattr(obj, self.attr)
6868

69-
class setter(object):
69+
class setter:
7070
def __init__(self, attr):
7171
self.attr = attr
7272
def __call__(self, obj, value):
7373
return setattr(obj, self.attr, value)
7474

75-
class deleter(object):
75+
class deleter:
7676
def __init__(self, attr):
7777
self.attr = attr
7878
def __call__(self, obj):
@@ -123,7 +123,7 @@ def __call__(self, obj, name):
123123
# Shared with PyPy:
124124

125125
def add_overload(match_class, match_method, overload):
126-
class method_pythonizor(object):
126+
class method_pythonizor:
127127
def __init__(self, match_class, match_method, overload):
128128
import re
129129
self.match_class = re.compile(match_class)
@@ -146,7 +146,7 @@ def __call__(self, obj, name):
146146

147147

148148
def compose_method(match_class, match_method, g):
149-
class composition_pythonizor(object):
149+
class composition_pythonizor:
150150
def __init__(self, match_class, match_method, g):
151151
import re
152152
self.match_class = re.compile(match_class)
@@ -174,7 +174,7 @@ def h(self, *args, **kwargs):
174174

175175

176176
def set_method_property(match_class, match_method, prop, value):
177-
class method_pythonizor(object):
177+
class method_pythonizor:
178178
def __init__(self, match_class, match_method, prop, value):
179179
import re
180180
self.match_class = re.compile(match_class)
@@ -196,7 +196,7 @@ def __call__(self, obj, name):
196196

197197

198198
def make_property(match_class, match_get, match_set=None, match_del=None, prop_name=None):
199-
class property_pythonizor(object):
199+
class property_pythonizor:
200200
def __init__(self, match_class, match_get, match_set, match_del, prop_name):
201201
import re
202202
self.match_class = re.compile(match_class)
@@ -230,7 +230,7 @@ def __init__(self, match_class, match_get, match_set, match_del, prop_name):
230230
self.prop_name = prop_name
231231

232232
def make_get_del_proxy(self, getter):
233-
class proxy(object):
233+
class proxy:
234234
def __init__(self, getter):
235235
self.getter = getter
236236

@@ -239,7 +239,7 @@ def __call__(self, obj):
239239
return proxy(getter)
240240

241241
def make_set_proxy(self, setter):
242-
class proxy(object):
242+
class proxy:
243243
def __init__(self, setter):
244244
self.setter = setter
245245

python/cppyy/interactive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
#- fake namespace for interactive lazy lookups -------------------------------
11-
class InteractiveLazy(object):
11+
class InteractiveLazy:
1212
def __init__(self, hook_okay):
1313
self._hook_okay = hook_okay
1414

python/cppyy/ll.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def argc():
4646
# import low-level python converters
4747
for _name in ['addressof', 'as_cobject', 'as_capsule', 'as_ctypes']:
4848
try:
49-
exec('%s = cppyy._backend.%s' % (_name, _name))
49+
exec('{} = cppyy._backend.{}'.format(_name, _name))
5050
__all__.append(_name)
5151
except AttributeError:
5252
pass
@@ -81,7 +81,7 @@ def argc():
8181

8282

8383
# helper for sizing arrays
84-
class ArraySizer(object):
84+
class ArraySizer:
8585
def __init__(self, func):
8686
self.func = func
8787
def __getitem__(self, t):

python/cppyy/numba_ext.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class CppFunctionNumbaType(nb_types.Callable):
112112
requires_gil = False
113113

114114
def __init__(self, func, is_method=False):
115-
super(CppFunctionNumbaType, self).__init__('CppFunction(%s)' % str(func))
115+
super().__init__('CppFunction(%s)' % str(func))
116116

117117
self.sig = None
118118
self._func = func
@@ -195,7 +195,7 @@ def __init__(self, dmm, fe_type):
195195
# the function pointer of this overload can not be exactly typed, but
196196
# only the storage size is relevant, so simply use a void*
197197
be_type = ir.PointerType(dmm.lookup(nb_types.void).get_value_type())
198-
super(CppFunctionModel, self).__init__(dmm, fe_type, be_type)
198+
super().__init__(dmm, fe_type, be_type)
199199

200200
@nb_iutils.lower_constant(CppFunctionNumbaType)
201201
def constant_function_pointer(context, builder, ty, pyval):
@@ -207,7 +207,7 @@ def constant_function_pointer(context, builder, ty, pyval):
207207
#
208208
# C++ method / data member -> Numba
209209
#
210-
class CppDataMemberInfo(object):
210+
class CppDataMemberInfo:
211211
__slots__ = ['f_name', 'f_offset', 'f_nbtype', 'f_irtype']
212212

213213
def __init__(self, name, offset, cpptype):
@@ -222,7 +222,7 @@ def __init__(self, name, offset, cpptype):
222222
#
223223
class CppClassNumbaType(CppFunctionNumbaType):
224224
def __init__(self, scope, qualifier):
225-
super(CppClassNumbaType, self).__init__(scope.__init__)
225+
super().__init__(scope.__init__)
226226
self.name = 'CppClass(%s)' % scope.__cpp_name__ # overrides value in Type
227227
self._scope = scope
228228
self._qualifier = qualifier
@@ -234,7 +234,7 @@ def get_qualifier(self):
234234
return self._qualifier
235235

236236
def get_call_type(self, context, args, kwds):
237-
sig = super(CppClassNumbaType, self).get_call_type(context, args, kwds)
237+
sig = super().get_call_type(context, args, kwds)
238238
self.sig = sig
239239
return sig
240240

@@ -428,7 +428,7 @@ def get_value_type(self):
428428

429429
# TODO: this doesn't work for real PODs, b/c those are unpacked into their elements and
430430
# passed through registers
431-
return ir.PointerType(super(ImplClassModel, self).get_value_type())
431+
return ir.PointerType(super().get_value_type())
432432

433433
# argument: representation used for function argument. Needs to be builtin type,
434434
# but unlike other Numba composites, C++ proxies are not flattened.

python/cppyy_compat/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def pypy58_57_compat():
1515
os.chdir(os.path.dirname(c._name))
1616
imp.init_builtin('cppyy')
1717
except ImportError:
18-
raise EnvironmentError('"%s" missing in LD_LIBRARY_PATH' %\
18+
raise OSError('"%s" missing in LD_LIBRARY_PATH' %\
1919
os.path.dirname(c._name))
2020
finally:
2121
os.chdir(olddir)
@@ -52,7 +52,7 @@ def py59_compat():
5252
actual_name = __name__; __name__ = ''
5353
import _cppyy as _backend
5454
except ImportError:
55-
raise EnvironmentError('"%s" missing in LD_LIBRARY_PATH' % os.path.dirname(c._name))
55+
raise OSError('"%s" missing in LD_LIBRARY_PATH' % os.path.dirname(c._name))
5656
finally:
5757
__name__ = actual_name
5858
os.chdir(olddir)

test/bindexplib.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import os, sys, subprocess
42

53
target = sys.argv[1]

0 commit comments

Comments
 (0)