Author: Brian Kearns <bdkea...@gmail.com> Branch: py3k Changeset: r71093:33694c682b75 Date: 2014-04-30 12:52 -0400 http://bitbucket.org/pypy/pypy/changeset/33694c682b75/
Log: port some improvements from default diff --git a/lib_pypy/_testcapi.py b/lib_pypy/_testcapi.py --- a/lib_pypy/_testcapi.py +++ b/lib_pypy/_testcapi.py @@ -13,9 +13,7 @@ try: fp, filename, description = imp.find_module('_testcapi', path=[output_dir]) - try: + with fp: imp.load_module('_testcapi', fp, filename, description) - finally: - fp.close() except ImportError: _pypy_testcapi.compile_shared(cfile, '_testcapi', output_dir) diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py --- a/pypy/interpreter/main.py +++ b/pypy/interpreter/main.py @@ -17,8 +17,8 @@ def compilecode(space, source, filename, cmd='exec'): w = space.wrap - w_code = space.builtin.call('compile', - space.wrapbytes(source), w(filename), w(cmd), w(0), w(0)) + w_code = space.builtin.call( + 'compile', space.wrapbytes(source), w(filename), w(cmd), w(0), w(0)) pycode = space.interp_w(eval.Code, w_code) return pycode diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -828,7 +828,7 @@ __kwdefaults__ = getset_func_kwdefaults, __annotations__ = getset_func_annotations, __globals__ = interp_attrproperty_w('w_func_globals', cls=Function), - __closure__ = GetSetProperty( Function.fget_func_closure ), + __closure__ = GetSetProperty(Function.fget_func_closure), __module__ = getset___module__, __weakref__ = make_weakref_descr(Function), ) diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py --- a/pypy/module/__builtin__/compiling.py +++ b/pypy/module/__builtin__/compiling.py @@ -27,22 +27,11 @@ """ from pypy.interpreter.pyopcode import source_as_str ec = space.getexecutioncontext() - if flags & ~(ec.compiler.compiler_flags | - consts.PyCF_ONLY_AST | - consts.PyCF_DONT_IMPLY_DEDENT | - consts.PyCF_SOURCE_IS_UTF8): + if flags & ~(ec.compiler.compiler_flags | consts.PyCF_ONLY_AST | + consts.PyCF_DONT_IMPLY_DEDENT | consts.PyCF_SOURCE_IS_UTF8): raise OperationError(space.w_ValueError, space.wrap("compile() unrecognized flags")) - flags |= consts.PyCF_SOURCE_IS_UTF8 - ast_node = source = None - if space.isinstance_w(w_source, space.gettypeobject(ast.AST.typedef)): - ast_node = space.interp_w(ast.mod, w_source) - ast_node.sync_app_attrs(space) - else: - source, flags = source_as_str(space, w_source, 'compile', - "string, bytes or AST", flags) - if not dont_inherit: caller = ec.gettopframe_nohidden() if caller: @@ -55,11 +44,18 @@ # XXX: optimize flag is not used - if ast_node is not None: + if space.isinstance_w(w_source, space.gettypeobject(ast.AST.typedef)): + ast_node = space.interp_w(ast.mod, w_source) + ast_node.sync_app_attrs(space) code = ec.compiler.compile_ast(ast_node, filename, mode, flags) - elif flags & consts.PyCF_ONLY_AST: - ast_node = ec.compiler.compile_to_ast(source, filename, mode, flags) - return space.wrap(ast_node) + return space.wrap(code) + + flags |= consts.PyCF_SOURCE_IS_UTF8 + source, flags = source_as_str(space, w_source, 'compile', + "string, bytes or AST", flags) + + if flags & consts.PyCF_ONLY_AST: + code = ec.compiler.compile_to_ast(source, filename, mode, flags) else: code = ec.compiler.compile(source, filename, mode, flags) return space.wrap(code) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit