Remove and ban use of py.builtin

This commit is contained in:
Anthony Sottile 2019-01-20 11:59:48 -08:00
parent 57bf9d6740
commit ec5e279f93
5 changed files with 15 additions and 10 deletions

View File

@ -51,3 +51,8 @@ repos:
entry: 'changelog files must be named ####.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst' entry: 'changelog files must be named ####.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst'
exclude: changelog/(\d+\.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst|README.rst|_template.rst) exclude: changelog/(\d+\.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst|README.rst|_template.rst)
files: ^changelog/ files: ^changelog/
- id: py-deprecated
name: py library is deprecated
language: pygrep
entry: '\bpy\.(builtin\.|code\.|std\.)'
types: [python]

View File

@ -237,9 +237,7 @@ def getfslineno(obj):
def findsource(obj): def findsource(obj):
try: try:
sourcelines, lineno = inspect.findsource(obj) sourcelines, lineno = inspect.findsource(obj)
except py.builtin._sysex: except Exception:
raise
except: # noqa
return None, -1 return None, -1
source = Source() source = Source()
source.lines = [line.rstrip() for line in sourcelines] source.lines = [line.rstrip() for line in sourcelines]

View File

@ -678,7 +678,7 @@ class AssertionRewriter(ast.NodeVisitor):
# Insert some special imports at the top of the module but after any # Insert some special imports at the top of the module but after any
# docstrings and __future__ imports. # docstrings and __future__ imports.
aliases = [ aliases = [
ast.alias(py.builtin.builtins.__name__, "@py_builtins"), ast.alias(six.moves.builtins.__name__, "@py_builtins"),
ast.alias("_pytest.assertion.rewrite", "@pytest_ar"), ast.alias("_pytest.assertion.rewrite", "@pytest_ar"),
] ]
doc = getattr(mod, "docstring", None) doc = getattr(mod, "docstring", None)

View File

@ -963,7 +963,7 @@ class TestTracebackCutting(object):
def test_filter_traceback_generated_code(self): def test_filter_traceback_generated_code(self):
"""test that filter_traceback() works with the fact that """test that filter_traceback() works with the fact that
py.code.Code.path attribute might return an str object. _pytest._code.code.Code.path attribute might return an str object.
In this case, one of the entries on the traceback was produced by In this case, one of the entries on the traceback was produced by
dynamically generated code. dynamically generated code.
See: https://bitbucket.org/pytest-dev/py/issues/71 See: https://bitbucket.org/pytest-dev/py/issues/71
@ -984,7 +984,7 @@ class TestTracebackCutting(object):
def test_filter_traceback_path_no_longer_valid(self, testdir): def test_filter_traceback_path_no_longer_valid(self, testdir):
"""test that filter_traceback() works with the fact that """test that filter_traceback() works with the fact that
py.code.Code.path attribute might return an str object. _pytest._code.code.Code.path attribute might return an str object.
In this case, one of the files in the traceback no longer exists. In this case, one of the files in the traceback no longer exists.
This fixes #1133. This fixes #1133.
""" """

View File

@ -7,7 +7,6 @@ import sys
import textwrap import textwrap
import attr import attr
import py
import six import six
import _pytest.assertion as plugin import _pytest.assertion as plugin
@ -455,10 +454,13 @@ class TestAssert_reprcompare(object):
assert len(expl) > 1 assert len(expl) > 1
def test_Sequence(self): def test_Sequence(self):
col = py.builtin._tryimport("collections.abc", "collections", "sys") if sys.version_info >= (3, 3):
if not hasattr(col, "MutableSequence"): import collections.abc as collections_abc
else:
import collections as collections_abc
if not hasattr(collections_abc, "MutableSequence"):
pytest.skip("cannot import MutableSequence") pytest.skip("cannot import MutableSequence")
MutableSequence = col.MutableSequence MutableSequence = collections_abc.MutableSequence
class TestSequence(MutableSequence): # works with a Sequence subclass class TestSequence(MutableSequence): # works with a Sequence subclass
def __init__(self, iterable): def __init__(self, iterable):