Merge pull request #3019 from srinivasreddy/rm_ast
remove '_ast' module; and redirect '_ast' references to 'ast'
This commit is contained in:
commit
771b5c8852
|
@ -1,19 +1,15 @@
|
||||||
from __future__ import absolute_import, division, generators, print_function
|
from __future__ import absolute_import, division, generators, print_function
|
||||||
|
|
||||||
|
import ast
|
||||||
|
from ast import PyCF_ONLY_AST as _AST_FLAG
|
||||||
from bisect import bisect_right
|
from bisect import bisect_right
|
||||||
import sys
|
import sys
|
||||||
import six
|
import six
|
||||||
import inspect
|
import inspect
|
||||||
import tokenize
|
import tokenize
|
||||||
import py
|
import py
|
||||||
cpy_compile = compile
|
|
||||||
|
|
||||||
try:
|
cpy_compile = compile
|
||||||
import _ast
|
|
||||||
from _ast import PyCF_ONLY_AST as _AST_FLAG
|
|
||||||
except ImportError:
|
|
||||||
_AST_FLAG = 0
|
|
||||||
_ast = None
|
|
||||||
|
|
||||||
|
|
||||||
class Source(object):
|
class Source(object):
|
||||||
|
@ -209,7 +205,7 @@ def compile_(source, filename=None, mode='exec', flags=generators.compiler_flag,
|
||||||
retrieval of the source code for the code object
|
retrieval of the source code for the code object
|
||||||
and any recursively created code objects.
|
and any recursively created code objects.
|
||||||
"""
|
"""
|
||||||
if _ast is not None and isinstance(source, _ast.AST):
|
if isinstance(source, ast.AST):
|
||||||
# XXX should Source support having AST?
|
# XXX should Source support having AST?
|
||||||
return cpy_compile(source, filename, mode, flags, dont_inherit)
|
return cpy_compile(source, filename, mode, flags, dont_inherit)
|
||||||
_genframe = sys._getframe(1) # the caller
|
_genframe = sys._getframe(1) # the caller
|
||||||
|
@ -322,7 +318,7 @@ def get_statement_startend2(lineno, node):
|
||||||
# AST's line numbers start indexing at 1
|
# AST's line numbers start indexing at 1
|
||||||
values = []
|
values = []
|
||||||
for x in ast.walk(node):
|
for x in ast.walk(node):
|
||||||
if isinstance(x, _ast.stmt) or isinstance(x, _ast.ExceptHandler):
|
if isinstance(x, ast.stmt) or isinstance(x, ast.ExceptHandler):
|
||||||
values.append(x.lineno - 1)
|
values.append(x.lineno - 1)
|
||||||
for name in "finalbody", "orelse":
|
for name in "finalbody", "orelse":
|
||||||
val = getattr(x, name, None)
|
val = getattr(x, name, None)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""Rewrite assertion AST to produce nice error messages"""
|
"""Rewrite assertion AST to produce nice error messages"""
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
import ast
|
import ast
|
||||||
import _ast
|
|
||||||
import errno
|
import errno
|
||||||
import itertools
|
import itertools
|
||||||
import imp
|
import imp
|
||||||
|
@ -914,7 +913,7 @@ class AssertionRewriter(ast.NodeVisitor):
|
||||||
def visit_Compare(self, comp):
|
def visit_Compare(self, comp):
|
||||||
self.push_format_context()
|
self.push_format_context()
|
||||||
left_res, left_expl = self.visit(comp.left)
|
left_res, left_expl = self.visit(comp.left)
|
||||||
if isinstance(comp.left, (_ast.Compare, _ast.BoolOp)):
|
if isinstance(comp.left, (ast.Compare, ast.BoolOp)):
|
||||||
left_expl = "({0})".format(left_expl)
|
left_expl = "({0})".format(left_expl)
|
||||||
res_variables = [self.variable() for i in range(len(comp.ops))]
|
res_variables = [self.variable() for i in range(len(comp.ops))]
|
||||||
load_names = [ast.Name(v, ast.Load()) for v in res_variables]
|
load_names = [ast.Name(v, ast.Load()) for v in res_variables]
|
||||||
|
@ -925,7 +924,7 @@ class AssertionRewriter(ast.NodeVisitor):
|
||||||
results = [left_res]
|
results = [left_res]
|
||||||
for i, op, next_operand in it:
|
for i, op, next_operand in it:
|
||||||
next_res, next_expl = self.visit(next_operand)
|
next_res, next_expl = self.visit(next_operand)
|
||||||
if isinstance(next_operand, (_ast.Compare, _ast.BoolOp)):
|
if isinstance(next_operand, (ast.Compare, ast.BoolOp)):
|
||||||
next_expl = "({0})".format(next_expl)
|
next_expl = "({0})".format(next_expl)
|
||||||
results.append(next_res)
|
results.append(next_res)
|
||||||
sym = binop_map[op.__class__]
|
sym = binop_map[op.__class__]
|
||||||
|
|
|
@ -5,11 +5,7 @@ import pprint
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
import py
|
import py
|
||||||
import six
|
import six
|
||||||
try:
|
from collections import Sequence
|
||||||
from collections import Sequence
|
|
||||||
except ImportError:
|
|
||||||
Sequence = list
|
|
||||||
|
|
||||||
|
|
||||||
u = six.text_type
|
u = six.text_type
|
||||||
|
|
||||||
|
@ -113,7 +109,7 @@ def assertrepr_compare(config, op, left, right):
|
||||||
summary = u('%s %s %s') % (ecu(left_repr), op, ecu(right_repr))
|
summary = u('%s %s %s') % (ecu(left_repr), op, ecu(right_repr))
|
||||||
|
|
||||||
def issequence(x):
|
def issequence(x):
|
||||||
return (isinstance(x, (list, tuple, Sequence)) and not isinstance(x, basestring))
|
return isinstance(x, Sequence) and not isinstance(x, basestring)
|
||||||
|
|
||||||
def istext(x):
|
def istext(x):
|
||||||
return isinstance(x, basestring)
|
return isinstance(x, basestring)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Clean up code by replacing imports and references of `_ast` to `ast`.
|
|
@ -8,13 +8,10 @@ import _pytest._code
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest._code import Source
|
from _pytest._code import Source
|
||||||
from _pytest._code.source import _ast
|
from _pytest._code.source import ast
|
||||||
|
|
||||||
if _ast is not None:
|
|
||||||
astonly = pytest.mark.nothing
|
|
||||||
else:
|
|
||||||
astonly = pytest.mark.xfail("True", reason="only works with AST-compile")
|
|
||||||
|
|
||||||
|
astonly = pytest.mark.nothing
|
||||||
failsonjython = pytest.mark.xfail("sys.platform.startswith('java')")
|
failsonjython = pytest.mark.xfail("sys.platform.startswith('java')")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue