Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit e8ddcf1

Browse files
committed
Merge branch 'topic/default/modernize' into 'branch/default'
Modernise syntax See merge request pypy/pypy!718
2 parents dc065fc + b885bea commit e8ddcf1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+644
-232
lines changed

rpython/annotator/binaryop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ def union((s_obj1, s_obj2)):
166166

167167
# cloning a function with identical code, for the can_only_throw attribute
168168
def _clone(f, can_only_throw = None):
169-
newfunc = type(f)(f.func_code, f.func_globals, f.func_name,
170-
f.func_defaults, f.func_closure)
169+
newfunc = type(f)(f.__code__, f.__globals__, f.__name__,
170+
f.__defaults__, f.__closure__)
171171
if can_only_throw is not None:
172172
newfunc.can_only_throw = can_only_throw
173173
return newfunc

rpython/annotator/bookkeeper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ def newfuncdesc(self, pyfunc):
415415
signature = Signature(['entry']) # haaaaaack
416416
defaults = ()
417417
else:
418-
signature = cpython_code_signature(pyfunc.func_code)
419-
defaults = pyfunc.func_defaults
418+
signature = cpython_code_signature(pyfunc.__code__)
419+
defaults = pyfunc.__defaults__
420420
# get the specializer based on the tag of the 'pyobj'
421421
# (if any), according to the current policy
422422
tag = getattr(pyfunc, '_annspecialcase_', None)
@@ -582,7 +582,7 @@ def warning(self, msg):
582582

583583
def origin_of_meth(boundmeth):
584584
func = boundmeth.im_func
585-
candname = func.func_name
585+
candname = func.__name__
586586
for cls in inspect.getmro(boundmeth.im_class):
587587
dict = cls.__dict__
588588
if dict.get(candname) is func:

rpython/flowspace/flowcontext.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def UNARY_OP(self, *ignored):
199199
w_1 = self.popvalue()
200200
w_result = operation(w_1).eval(self)
201201
self.pushvalue(w_result)
202-
UNARY_OP.func_name = OPCODE
202+
UNARY_OP.__name__ = OPCODE
203203
return UNARY_OP
204204

205205
_binary_ops = [
@@ -237,7 +237,7 @@ def BINARY_OP(self, _):
237237
w_1 = self.popvalue()
238238
w_result = operation(w_1, w_2).eval(self)
239239
self.pushvalue(w_result)
240-
BINARY_OP.func_name = OPCODE
240+
BINARY_OP.__name__ = OPCODE
241241
return BINARY_OP
242242

243243
_unsupported_ops = [
@@ -258,7 +258,7 @@ def BINARY_OP(self, _):
258258
def unsupportedoperation(OPCODE, msg):
259259
def UNSUPPORTED(self, *ignored):
260260
raise FlowingError("%s is not RPython" % (msg,))
261-
UNSUPPORTED.func_name = OPCODE
261+
UNSUPPORTED.__name__ = OPCODE
262262
return UNSUPPORTED
263263

264264
compare_method = [
@@ -281,10 +281,10 @@ def __init__(self, graph, code):
281281
self.graph = graph
282282
func = graph.func
283283
self.pycode = code
284-
self.w_globals = Constant(func.func_globals)
284+
self.w_globals = Constant(func.__globals__)
285285
self.blockstack = []
286286

287-
self.init_closure(func.func_closure)
287+
self.init_closure(func.__closure__)
288288
self.f_lineno = code.co_firstlineno
289289
self.last_offset = 0
290290

rpython/flowspace/generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AbstractPosition(object):
1818
def make_generator_entry_graph(func):
1919
# This is the first copy of the graph. We replace it with
2020
# a small bootstrap graph.
21-
code = HostCode._from_code(func.func_code)
21+
code = HostCode._from_code(func.__code__)
2222
graph = PyGraph(func, code)
2323
block = graph.startblock
2424
for name, w_value in zip(code.co_varnames, block.framestate.mergeable):
@@ -69,7 +69,7 @@ def replace_graph_with_bootstrap(GeneratorIterator, graph):
6969

7070
def attach_next_method(GeneratorIterator, graph):
7171
func = graph.func
72-
func = func_with_new_name(func, '%s__next' % (func.func_name,))
72+
func = func_with_new_name(func, '%s__next' % (func.__name__,))
7373
func._generator_next_method_of_ = GeneratorIterator
7474
func._always_inline_ = True
7575
#

rpython/flowspace/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def source(self, value):
4848

4949
@property
5050
def startline(self):
51-
return self.func.func_code.co_firstlineno
51+
return self.func.__code__.co_firstlineno
5252

5353
@property
5454
def filename(self):
55-
return self.func.func_code.co_filename
55+
return self.func.__code__.co_filename
5656

5757
def __str__(self):
5858
if hasattr(self, 'func'):

rpython/flowspace/objspace.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414
def _assert_rpythonic(func):
1515
"""Raise ValueError if ``func`` is obviously not RPython"""
1616
try:
17-
func.func_code.co_cellvars
17+
func.__code__.co_cellvars
1818
except AttributeError:
1919
raise ValueError("%r is not RPython: it is likely an unexpected "
2020
"built-in function or type" % (func,))
2121
if getattr(func, "_not_rpython_", False):
2222
raise ValueError("%r is tagged as @not_rpython" % (func,))
23-
if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
23+
if func.__doc__ and func.__doc__.lstrip().startswith('NOT_RPYTHON'):
2424
raise ValueError("%r is tagged as NOT_RPYTHON" % (func,))
25-
if func.func_code.co_cellvars:
25+
if func.__code__.co_cellvars:
2626
raise ValueError(
2727
"""RPython functions cannot create closures
2828
Possible causes:
2929
Function is inner function
3030
Function uses generator expressions
3131
Lambda expressions
3232
in %r""" % (func,))
33-
if not (func.func_code.co_flags & CO_NEWLOCALS):
33+
if not (func.__code__.co_flags & CO_NEWLOCALS):
3434
raise ValueError("The code object for a RPython function should have "
3535
"the flag CO_NEWLOCALS set.")
3636

@@ -43,7 +43,7 @@ def build_flow(func):
4343
if (isgeneratorfunction(func) and
4444
not hasattr(func, '_generator_next_method_of_')):
4545
return make_generator_entry_graph(func)
46-
code = HostCode._from_code(func.func_code)
46+
code = HostCode._from_code(func.__code__)
4747
graph = PyGraph(func, code)
4848
ctx = FlowContext(graph, code)
4949
ctx.build_flow()

rpython/flowspace/pygraph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def __init__(self, func, code):
1919
super(PyGraph, self).__init__(self._sanitize_funcname(func), initialblock)
2020
self.func = func
2121
self.signature = code.signature
22-
self.defaults = func.func_defaults or ()
22+
self.defaults = func.__defaults__ or ()
2323

2424
@staticmethod
2525
def _sanitize_funcname(func):
2626
# CallableFactory.pycall may add class_ to functions that are methods
27-
name = func.func_name
27+
name = func.__name__
2828
class_ = getattr(func, 'class_', None)
2929
if class_ is not None:
3030
name = '%s.%s' % (class_.__name__, name)

rpython/flowspace/test/test_framestate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def get_context(self, func):
1010
func = func.im_func
1111
except AttributeError:
1212
pass
13-
code = HostCode._from_code(func.func_code)
13+
code = HostCode._from_code(func.__code__)
1414
graph = PyGraph(func, code)
1515
ctx = FlowContext(graph, code)
1616
# hack the frame

rpython/flowspace/test/test_objspace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ def f():
10151015

10161016
# this code is generated by pypy-c when compiling above f
10171017
pypy_code = 't\x00\x00\x83\x00\x00}\x00\x00|\x00\x00\xc9\x01\x00\xca\x00\x00S'
1018-
new_c = self.monkey_patch_code(f.func_code, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',))
1018+
new_c = self.monkey_patch_code(f.__code__, 3, 3, pypy_code, ('X', 'x', 'm'), ('x',))
10191019
f2 = types.FunctionType(new_c, locals(), 'f')
10201020

10211021
graph = self.codetest(f2)
@@ -1034,7 +1034,7 @@ def f():
10341034

10351035
# this code is generated by pypy-c when compiling above f
10361036
pypy_code = 'd\x01\x00\xcb\x00\x00D]\x0c\x00}\x00\x00|\x00\x00^\x02\x00q\x07\x00S'
1037-
new_c = self.monkey_patch_code(f.func_code, 3, 67, pypy_code, (),
1037+
new_c = self.monkey_patch_code(f.__code__, 3, 67, pypy_code, (),
10381038
('i',))
10391039
f2 = types.FunctionType(new_c, locals(), 'f')
10401040

rpython/jit/backend/llgraph/runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ def _op_default_implementation(self, descr, *args):
15891589
# for all operations implemented in the blackhole interpreter
15901590
return func(*args)
15911591
#
1592-
_op_default_implementation.func_name = 'execute_' + opname
1592+
_op_default_implementation.__name__ = 'execute_' + opname
15931593
return _op_default_implementation
15941594

15951595
def _new_execute(opname):
@@ -1613,7 +1613,7 @@ def execute(self, descr, *args):
16131613
if count == 1:
16141614
result = result[0]
16151615
return result
1616-
execute.func_name = 'execute_' + opname
1616+
execute.__name__ = 'execute_' + opname
16171617
return execute
16181618

16191619
for k, v in rop.__dict__.iteritems():

0 commit comments

Comments
 (0)