Skip to content

Commit b70f370

Browse files
committed
Remove legacy code guarded by sys.version_info
1 parent 121c530 commit b70f370

File tree

2 files changed

+7
-71
lines changed

2 files changed

+7
-71
lines changed

src/_pytest/_code/code.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ def repr_traceback(self, excinfo):
715715
if self.tbfilter:
716716
traceback = traceback.filter()
717717

718-
if is_recursion_error(excinfo):
718+
if excinfo.errisinstance(RecursionError):
719719
traceback, extraline = self._truncate_recursive_traceback(traceback)
720720
else:
721721
extraline = None
@@ -1007,23 +1007,6 @@ def getrawcode(obj, trycall=True):
10071007
return obj
10081008

10091009

1010-
if sys.version_info[:2] >= (3, 5): # RecursionError introduced in 3.5
1011-
1012-
def is_recursion_error(excinfo):
1013-
return excinfo.errisinstance(RecursionError) # noqa
1014-
1015-
1016-
else:
1017-
1018-
def is_recursion_error(excinfo):
1019-
if not excinfo.errisinstance(RuntimeError):
1020-
return False
1021-
try:
1022-
return "maximum recursion depth exceeded" in str(excinfo.value)
1023-
except UnicodeError:
1024-
return False
1025-
1026-
10271010
# relative paths that we use to filter traceback entries from appearing to the user;
10281011
# see filter_traceback
10291012
# note: if we need to add more paths than what we have now we should probably use a list

src/_pytest/assertion/rewrite.py

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@
4444
PYC_EXT = ".py" + (__debug__ and "c" or "o")
4545
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
4646

47-
if sys.version_info >= (3, 5):
48-
ast_Call = ast.Call
49-
else:
50-
51-
def ast_Call(a, b, c):
52-
return ast.Call(a, b, c, None, None)
53-
5447

5548
class AssertionRewritingHook(object):
5649
"""PEP302 Import hook which rewrites asserts."""
@@ -702,7 +695,7 @@ def helper(self, name, *args):
702695
"""Call a helper in this module."""
703696
py_name = ast.Name("@pytest_ar", ast.Load())
704697
attr = ast.Attribute(py_name, name, ast.Load())
705-
return ast_Call(attr, list(args), [])
698+
return ast.Call(attr, list(args), [])
706699

707700
def builtin(self, name):
708701
"""Return the builtin called *name*."""
@@ -812,7 +805,7 @@ def visit_Assert(self, assert_):
812805
msg = self.pop_format_context(template)
813806
fmt = self.helper("_format_explanation", msg)
814807
err_name = ast.Name("AssertionError", ast.Load())
815-
exc = ast_Call(err_name, [fmt], [])
808+
exc = ast.Call(err_name, [fmt], [])
816809
raise_ = ast.Raise(exc, None)
817810

818811
body.append(raise_)
@@ -856,7 +849,7 @@ def warn_about_none_ast(self, node, module_path, lineno):
856849
def visit_Name(self, name):
857850
# Display the repr of the name if it's a local variable or
858851
# _should_repr_global_name() thinks it's acceptable.
859-
locs = ast_Call(self.builtin("locals"), [], [])
852+
locs = ast.Call(self.builtin("locals"), [], [])
860853
inlocs = ast.Compare(ast.Str(name.id), [ast.In()], [locs])
861854
dorepr = self.helper("_should_repr_global_name", name)
862855
test = ast.BoolOp(ast.Or(), [inlocs, dorepr])
@@ -883,7 +876,7 @@ def visit_BoolOp(self, boolop):
883876
res, expl = self.visit(v)
884877
body.append(ast.Assign([ast.Name(res_var, ast.Store())], res))
885878
expl_format = self.pop_format_context(ast.Str(expl))
886-
call = ast_Call(app, [expl_format], [])
879+
call = ast.Call(app, [expl_format], [])
887880
self.on_failure.append(ast.Expr(call))
888881
if i < levels:
889882
cond = res
@@ -912,9 +905,9 @@ def visit_BinOp(self, binop):
912905
res = self.assign(ast.BinOp(left_expr, binop.op, right_expr))
913906
return res, explanation
914907

915-
def visit_Call_35(self, call):
908+
def visit_Call(self, call):
916909
"""
917-
visit `ast.Call` nodes on Python3.5 and after
910+
visit `ast.Call` nodes
918911
"""
919912
if isinstance(call.func, ast.Name) and call.func.id == "all":
920913
return self._visit_all(call)
@@ -968,46 +961,6 @@ def visit_Starred(self, starred):
968961
new_starred = ast.Starred(res, starred.ctx)
969962
return new_starred, "*" + expl
970963

971-
def visit_Call_legacy(self, call):
972-
"""
973-
visit `ast.Call nodes on 3.4 and below`
974-
"""
975-
if isinstance(call.func, ast.Name) and call.func.id == "all":
976-
return self._visit_all(call)
977-
new_func, func_expl = self.visit(call.func)
978-
arg_expls = []
979-
new_args = []
980-
new_kwargs = []
981-
new_star = new_kwarg = None
982-
for arg in call.args:
983-
res, expl = self.visit(arg)
984-
new_args.append(res)
985-
arg_expls.append(expl)
986-
for keyword in call.keywords:
987-
res, expl = self.visit(keyword.value)
988-
new_kwargs.append(ast.keyword(keyword.arg, res))
989-
arg_expls.append(keyword.arg + "=" + expl)
990-
if call.starargs:
991-
new_star, expl = self.visit(call.starargs)
992-
arg_expls.append("*" + expl)
993-
if call.kwargs:
994-
new_kwarg, expl = self.visit(call.kwargs)
995-
arg_expls.append("**" + expl)
996-
expl = "%s(%s)" % (func_expl, ", ".join(arg_expls))
997-
new_call = ast.Call(new_func, new_args, new_kwargs, new_star, new_kwarg)
998-
res = self.assign(new_call)
999-
res_expl = self.explanation_param(self.display(res))
1000-
outer_expl = "%s\n{%s = %s\n}" % (res_expl, res_expl, expl)
1001-
return res, outer_expl
1002-
1003-
# ast.Call signature changed on 3.5,
1004-
# conditionally change which methods is named
1005-
# visit_Call depending on Python version
1006-
if sys.version_info >= (3, 5):
1007-
visit_Call = visit_Call_35
1008-
else:
1009-
visit_Call = visit_Call_legacy
1010-
1011964
def visit_Attribute(self, attr):
1012965
if not isinstance(attr.ctx, ast.Load):
1013966
return self.generic_visit(attr)

0 commit comments

Comments
 (0)