diff options
author | hippo91 <guillaume.peillex@gmail.com> | 2021-02-07 17:21:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-07 17:21:24 +0100 |
commit | 4944abaa7a1db6f3e59b9b5aaa58aef8e42eb55d (patch) | |
tree | c8192098c75040e8197e5dcaf23bd8b6ffe2ca57 | |
parent | 599fe72a0c0e07e2a7720237c40800aa3c611708 (diff) | |
parent | 6e735dc59aefcd12f7b8b8198fe349fb6615b6aa (diff) | |
download | astroid-git-4944abaa7a1db6f3e59b9b5aaa58aef8e42eb55d.tar.gz |
Merge pull request #889 from hippo91/dgilman-master
Thanks a lot @dgilman
-rw-r--r-- | .travis.yml | 10 | ||||
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | appveyor.yml | 9 | ||||
-rw-r--r-- | astroid/__pkginfo__.py | 2 | ||||
-rw-r--r-- | astroid/brain/brain_builtin_inference.py | 9 | ||||
-rw-r--r-- | astroid/brain/brain_hashlib.py | 9 | ||||
-rw-r--r-- | astroid/brain/brain_multiprocessing.py | 5 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | tests/unittest_brain.py | 28 | ||||
-rw-r--r-- | tests/unittest_helpers.py | 3 | ||||
-rw-r--r-- | tests/unittest_inference.py | 40 | ||||
-rw-r--r-- | tests/unittest_manager.py | 4 | ||||
-rw-r--r-- | tests/unittest_nodes.py | 30 | ||||
-rw-r--r-- | tests/unittest_object_model.py | 3 | ||||
-rw-r--r-- | tests/unittest_objects.py | 2 | ||||
-rw-r--r-- | tests/unittest_protocols.py | 6 | ||||
-rw-r--r-- | tests/unittest_python3.py | 23 | ||||
-rw-r--r-- | tests/unittest_raw_building.py | 2 | ||||
-rw-r--r-- | tests/unittest_regrtest.py | 2 | ||||
-rw-r--r-- | tests/unittest_scoped_nodes.py | 33 | ||||
-rw-r--r-- | tox.ini | 13 |
21 files changed, 67 insertions, 175 deletions
diff --git a/.travis.yml b/.travis.yml index d30c9386..9f2b24f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,18 +9,16 @@ jobs: env: TOXENV=pylint - python: 3.6 env: TOXENV=formatting - - python: 3.5 - env: TOXENV=py35 - python: pypy3 env: TOXENV=pypy - python: 3.6 - env: TOXENV=py36 + env: TOXENV=py36,py36-six - python: 3.7 - env: TOXENV=py37 + env: TOXENV=py37,py37-six - python: 3.8 - env: TOXENV=py38 + env: TOXENV=py38,py38-six - python: 3.9 - env: TOXENV=py39 + env: TOXENV=py39,py39-six before_install: - python --version - uname -a @@ -6,6 +6,12 @@ What's New in astroid 2.5.0? ============================ Release Date: TBA +* Remove support for Python 3.5. +* Remove the runtime dependency on ``six``. The ``six`` brain remains in + astroid. + + Fixes PyCQA/astroid#863 + * Enrich the ``brain_collection`` module so that ``__class_getitem__`` method is added to `deque` for ``python`` version above 3.9. @@ -22,6 +28,7 @@ Release Date: TBA Fixes PyCQA/pylint#4034 + * Adds `degrees`, `radians`, which are `numpy ufunc` functions, in the `numpy` brain. Adds `random` function in the `numpy.random` brain. Fixes PyCQA/pylint#3856 diff --git a/appveyor.yml b/appveyor.yml index dd6e193a..bc0eb66b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,17 +4,14 @@ cache: - 'C:\\tmp' environment: matrix: - - PYTHON: "C:\\Python35" - TOXENV: "py35" - - PYTHON: "C:\\Python36" - TOXENV: "py36" + TOXENV: "py36,py36-six" - PYTHON: "C:\\Python37" - TOXENV: "py37" + TOXENV: "py37,py37-six" - PYTHON: "C:\\Python38" - TOXENV: "py38" + TOXENV: "py38,py38-six" init: - ps: echo $env:TOXENV diff --git a/astroid/__pkginfo__.py b/astroid/__pkginfo__.py index 150b11c9..4dd627a9 100644 --- a/astroid/__pkginfo__.py +++ b/astroid/__pkginfo__.py @@ -29,7 +29,6 @@ numversion = tuple(int(elem) for elem in version.split(".") if elem.isdigit()) extras_require = {} install_requires = [ "lazy_object_proxy>=1.4.0", - "six~=1.12", "wrapt>=1.11,<1.13", 'typed-ast>=1.4.0,<1.5;implementation_name== "cpython" and python_version<"3.8"', ] @@ -49,7 +48,6 @@ classifiers = [ "Topic :: Software Development :: Quality Assurance", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index b1f811d4..b7659cc9 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -19,7 +19,6 @@ from functools import partial from textwrap import dedent -import six from astroid import ( MANAGER, UseInferenceDefault, @@ -237,9 +236,7 @@ def _container_generic_transform(arg, context, klass, iterables, build_elts): if not all(isinstance(elt[0], nodes.Const) for elt in arg.items): raise UseInferenceDefault() elts = [item[0].value for item in arg.items] - elif isinstance(arg, nodes.Const) and isinstance( - arg.value, (six.string_types, six.binary_type) - ): + elif isinstance(arg, nodes.Const) and isinstance(arg.value, (str, bytes)): elts = arg.value else: return @@ -447,9 +444,7 @@ def _infer_getattr_args(node, context): # which is unknown. return util.Uninferable, util.Uninferable - is_string = isinstance(attr, nodes.Const) and isinstance( - attr.value, six.string_types - ) + is_string = isinstance(attr, nodes.Const) and isinstance(attr.value, str) if not is_string: raise UseInferenceDefault diff --git a/astroid/brain/brain_hashlib.py b/astroid/brain/brain_hashlib.py index 95893628..9351f938 100644 --- a/astroid/brain/brain_hashlib.py +++ b/astroid/brain/brain_hashlib.py @@ -7,8 +7,6 @@ # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER import sys -import six - import astroid PY36 = sys.version_info >= (3, 6) @@ -55,12 +53,7 @@ def _hashlib_transform(): {"blake2b": blake2b_signature, "blake2s": blake2s_signature} ) classes = "".join( - template - % { - "name": hashfunc, - "digest": 'b""' if six.PY3 else '""', - "signature": signature, - } + template % {"name": hashfunc, "digest": 'b""', "signature": signature} for hashfunc, signature in algorithms_with_signature.items() ) return astroid.parse(classes) diff --git a/astroid/brain/brain_multiprocessing.py b/astroid/brain/brain_multiprocessing.py index 4ffd9780..dc93a27b 100644 --- a/astroid/brain/brain_multiprocessing.py +++ b/astroid/brain/brain_multiprocessing.py @@ -54,8 +54,7 @@ def _multiprocessing_managers_transform(): import array import threading import multiprocessing.pool as pool - - import six + import queue class Namespace(object): pass @@ -76,7 +75,7 @@ def _multiprocessing_managers_transform(): return array.array(typecode, sequence) class SyncManager(object): - Queue = JoinableQueue = six.moves.queue.Queue + Queue = JoinableQueue = queue.Queue Event = threading.Event RLock = threading.RLock BoundedSemaphore = threading.BoundedSemaphore @@ -49,7 +49,7 @@ def install(): author=author, author_email=author_email, url=web, - python_requires=">=3.5", + python_requires=">=3.6", install_requires=install_requires, extras_require=extras_require, packages=find_packages(exclude=["tests"]) + ["astroid.brain"], diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py index 1c004a06..45289550 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -32,6 +32,7 @@ import io import queue import re +import os try: import multiprocessing # pylint: disable=unused-import @@ -79,13 +80,20 @@ try: except ImportError: HAS_ATTR = False +try: + import six # pylint: disable=unused-import + + HAS_SIX = True +except ImportError: + HAS_SIX = False + from astroid import MANAGER from astroid import bases from astroid import builder from astroid import nodes from astroid import util -from astroid import test_utils import astroid +import astroid.test_utils as test_utils class HashlibTest(unittest.TestCase): @@ -108,7 +116,6 @@ class HashlibTest(unittest.TestCase): class_obj = hashlib_module[class_name] self._assert_hashlib_class(class_obj) - @test_utils.require_version(minver="3.6") def test_hashlib_py36(self): hashlib_module = MANAGER.ast_from_module_name("hashlib") for class_name in ["sha3_224", "sha3_512", "shake_128"]: @@ -134,7 +141,6 @@ class CollectionsDequeTests(unittest.TestCase): inferred = self._inferred_queue_instance() self.assertTrue(inferred.getattr("__len__")) - @test_utils.require_version(minver="3.5") def test_deque_py35methods(self): inferred = self._inferred_queue_instance() self.assertIn("copy", inferred.locals) @@ -164,7 +170,6 @@ class OrderedDictTest(unittest.TestCase): ) return next(node.infer()) - @test_utils.require_version(minver="3.4") def test_ordered_dict_py34method(self): inferred = self._inferred_ordered_dict_instance() self.assertIn("move_to_end", inferred.locals) @@ -216,9 +221,9 @@ class NamedTupleTest(unittest.TestCase): # namedtuple call and a mixin as base classes result = builder.extract_node( """ - import six + from urllib.parse import urlparse - result = __(six.moves.urllib.parse.urlparse('gopher://')) + result = __(urlparse('gopher://')) """ ) instance = next(result.infer()) @@ -403,7 +408,14 @@ class NoseBrainTest(unittest.TestCase): self.assertEqual(assert_equals.qname(), "unittest.case.TestCase.assertEqual") +@unittest.skipUnless(HAS_SIX, "These tests require the six library") class SixBrainTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + tox_env = os.environ.get("TOX_ENV_NAME") + if tox_env and not tox_env.endswith("-six") and HAS_SIX: + raise Exception("six was installed in a non-six testing environment.") + def test_attribute_access(self): ast_nodes = builder.extract_node( """ @@ -814,7 +826,6 @@ class EnumBrainTest(unittest.TestCase): inferred_string = next(node.infer()) assert inferred_string.value == "\N{NULL}" - @test_utils.require_version(minver="3.6") def test_dont_crash_on_for_loops_in_body(self): node = builder.extract_node( """ @@ -1162,7 +1173,6 @@ class ReBrainTest(unittest.TestCase): self.assertEqual(next(re_ast[name].infer()).value, getattr(re, name)) -@test_utils.require_version("3.6") class BrainFStrings(unittest.TestCase): def test_no_crash_on_const_reconstruction(self): node = builder.extract_node( @@ -1180,7 +1190,6 @@ class BrainFStrings(unittest.TestCase): self.assertIs(inferred, util.Uninferable) -@test_utils.require_version("3.6") class BrainNamedtupleAnnAssignTest(unittest.TestCase): def test_no_crash_on_ann_assign_in_namedtuple(self): node = builder.extract_node( @@ -1282,7 +1291,6 @@ class AttrsTest(unittest.TestCase): """ next(astroid.extract_node(code).infer()) - @test_utils.require_version(minver="3.6") def test_attrs_with_annotation(self): code = """ import attr diff --git a/tests/unittest_helpers.py b/tests/unittest_helpers.py index ced5fc0a..31c40712 100644 --- a/tests/unittest_helpers.py +++ b/tests/unittest_helpers.py @@ -14,7 +14,6 @@ from astroid import exceptions from astroid import helpers from astroid import manager from astroid import raw_building -from astroid import test_utils from astroid import util @@ -106,7 +105,6 @@ class TestHelpers(unittest.TestCase): expected_type = self._build_custom_builtin(expected) self.assert_classes_equal(node_type, expected_type) - @test_utils.require_version(minver="3.0") def test_object_type_metaclasses(self): module = builder.parse( """ @@ -123,7 +121,6 @@ class TestHelpers(unittest.TestCase): instance_type = helpers.object_type(meta_instance) self.assert_classes_equal(instance_type, module["Meta"]) - @test_utils.require_version(minver="3.0") def test_object_type_most_derived(self): node = builder.extract_node( """ diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index 1512456e..e580ee2a 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -996,7 +996,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): inferred = next(node.infer()) self.assertEqual(inferred.value, expected_value) - @test_utils.require_version(minver="3.5") def test_matmul(self): node = extract_node( """ @@ -1241,7 +1240,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(variable_a.inferred()[0].value, 2) @pytest.mark.xfail(reason="Relying on path copy") - @test_utils.require_version(minver="3.5") def test_nonregr_layed_dictunpack(self): """Regression test for https://github.com/PyCQA/astroid/issues/483 Make sure multiple dictunpack references are inferable @@ -1736,7 +1734,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertIsInstance(inferred, Instance) self.assertEqual(inferred.qname(), "{}.tuple".format(BUILTINS)) - @test_utils.require_version("3.5") def test_starred_in_tuple_literal(self): code = """ var = (1, 2, 3) @@ -1755,7 +1752,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertInferTuple(ast[3], [0, 1, 2, 3, 4, 5, 6, 7, 8]) self.assertInferTuple(ast[4], [0, 1, 2, 3, 4, 5, 6, 7, 999, 1000, 1001]) - @test_utils.require_version("3.5") def test_starred_in_list_literal(self): code = """ var = (1, 2, 3) @@ -1774,7 +1770,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertInferList(ast[3], [0, 1, 2, 3, 4, 5, 6, 7, 8]) self.assertInferList(ast[4], [0, 1, 2, 3, 4, 5, 6, 7, 999, 1000, 1001]) - @test_utils.require_version("3.5") def test_starred_in_set_literal(self): code = """ var = (1, 2, 3) @@ -1793,7 +1788,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertInferSet(ast[3], [0, 1, 2, 3, 4, 5, 6, 7, 8]) self.assertInferSet(ast[4], [0, 1, 2, 3, 4, 5, 6, 7, 999, 1000, 1001]) - @test_utils.require_version("3.5") def test_starred_in_literals_inference_issues(self): code = """ {0, *var} #@ @@ -1807,7 +1801,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): with self.assertRaises(InferenceError): next(node.infer()) - @test_utils.require_version("3.5") def test_starred_in_mapping_literal(self): code = """ var = {1: 'b', 2: 'c'} @@ -1823,7 +1816,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): ast[2], {0: "a", 1: "b", 2: "c", 3: "d", 4: "e", 5: "f", 6: "g"} ) - @test_utils.require_version("3.5") def test_starred_in_mapping_literal_no_inference_possible(self): node = extract_node( """ @@ -1841,7 +1833,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): ) self.assertEqual(next(node.infer()), util.Uninferable) - @test_utils.require_version("3.5") def test_starred_in_mapping_inference_issues(self): code = """ {0: 'a', **var} #@ @@ -1853,7 +1844,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): with self.assertRaises(InferenceError): next(node.infer()) - @test_utils.require_version("3.5") def test_starred_in_mapping_literal_non_const_keys_values(self): code = """ a, b, c, d, e, f, g, h, i, j = "ABCDEFGHIJ" @@ -1974,7 +1964,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertInferTuple(ast_nodes[3], [1, 3]) self.assertInferSet(ast_nodes[4], [1, 2]) - @test_utils.require_version("3.0") def test_builtin_inference_py3k(self): code = """ list(b"abc") #@ @@ -2034,7 +2023,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): ast_node = extract_node("""dict(a=1, b=2, **{'c': 3})""") self.assertInferDict(ast_node, {"a": 1, "b": 2, "c": 3}) - @test_utils.require_version("3.5") def test_dict_inference_for_multiple_starred(self): pairs = [ ('dict(a=1, **{"b": 2}, **{"c":3})', {"a": 1, "b": 2, "c": 3}), @@ -2045,7 +2033,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): node = extract_node(code) self.assertInferDict(node, expected_value) - @test_utils.require_version("3.5") def test_dict_inference_unpack_repeated_key(self): """Make sure astroid does not infer repeated keys in a dictionary @@ -2985,9 +2972,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): class Meta(type): def __getitem__(cls, arg): return 24 - import six - @six.add_metaclass(Meta) - class A(object): + class A(object, metaclass=Meta): pass A['Awesome'] #@ @@ -3020,9 +3005,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): class Meta(type): def __or__(self, other): return 24 - import six - @six.add_metaclass(Meta) - class A(object): + class A(object, metaclass=Meta): pass A | A @@ -3374,12 +3357,10 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): def test_unary_op_classes(self): ast_node = extract_node( """ - import six class Meta(type): def __invert__(self): return 42 - @six.add_metaclass(Meta) - class A(object): + class A(object, metaclass=Meta): pass ~A """ @@ -3674,16 +3655,13 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): # they will be in the future. ast_node = extract_node( """ - import six - class BookMeta(type): author = 'Rushdie' def metaclass_function(*args): return BookMeta - @six.add_metaclass(metaclass_function) - class Book(object): + class Book(object, metaclass=metaclass_function): pass Book #@ """ @@ -3788,9 +3766,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): class A(type): def test(cls): return cls - import six - @six.add_metaclass(A) - class B(object): + class B(object, metaclass=A): pass B.test() #@ @@ -3864,7 +3840,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertIsInstance(inferred, nodes.ClassDef) self.assertEqual(inferred.name, "A") - @test_utils.require_version(minver="3.0") def test_metaclass_with_keyword_args(self): ast_node = extract_node( """ @@ -4498,7 +4473,6 @@ class ArgumentsTest(unittest.TestCase): self.assertIsInstance(inferred, nodes.Tuple) self.assertEqual(self._get_tuple_value(inferred), expected_value) - @test_utils.require_version("3.5") def test_multiple_starred_args(self): expected_values = [(1, 2, 3), (1, 4, 2, 3, 5, 6, 7)] ast_nodes = extract_node( @@ -4531,7 +4505,6 @@ class ArgumentsTest(unittest.TestCase): self.assertIsInstance(inferred, nodes.Const) self.assertEqual(inferred.value, expected_value) - @test_utils.require_version("3.0") def test_kwonly_args(self): expected_values = [24, 24, 42, 23, 24, 24, 54] ast_nodes = extract_node( @@ -4614,7 +4587,6 @@ class ArgumentsTest(unittest.TestCase): self.assertIsInstance(inferred, nodes.Const, inferred) self.assertEqual(inferred.value, value) - @test_utils.require_version("3.5") def test_multiple_kwargs(self): expected_value = [("a", 1), ("b", 2), ("c", 3), ("d", 4), ("f", 42)] ast_node = extract_node( @@ -4761,7 +4733,6 @@ class CallSiteTest(unittest.TestCase): for pair in pairs: self._test_call_site_pair(*pair) - @test_utils.require_version("3.5") def test_call_site_starred_args(self): pairs = [ ( @@ -5251,7 +5222,6 @@ def test_builtin_inference_list_of_exceptions(): assert as_string.strip() == "(ValueError, TypeError)" -@test_utils.require_version(minver="3.6") def test_cannot_getattr_ann_assigns(): node = extract_node( """ diff --git a/tests/unittest_manager.py b/tests/unittest_manager.py index 91a781c6..63bbefeb 100644 --- a/tests/unittest_manager.py +++ b/tests/unittest_manager.py @@ -16,6 +16,7 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER +import builtins import os import platform import site @@ -23,7 +24,6 @@ import sys import unittest import pkg_resources -import six import time import astroid @@ -32,7 +32,7 @@ from astroid import manager from . import resources -BUILTINS = six.moves.builtins.__name__ +BUILTINS = builtins.__name__ def _get_file_from_object(obj): diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py index 0ba6b3e5..3396f91e 100644 --- a/tests/unittest_nodes.py +++ b/tests/unittest_nodes.py @@ -21,6 +21,7 @@ """tests for specific behaviour of astroid nodes """ +import builtins import os import sys import textwrap @@ -29,7 +30,6 @@ import copy import platform import pytest -import six import astroid from astroid import bases @@ -46,7 +46,7 @@ from . import resources abuilder = builder.AstroidBuilder() -BUILTINS = six.moves.builtins.__name__ +BUILTINS = builtins.__name__ PY38 = sys.version_info[:2] >= (3, 8) try: import typed_ast # pylint: disable=unused-import @@ -67,7 +67,6 @@ class AsStringTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(build("(1, )").as_string(), "(1, )") self.assertEqual(build("1, 2, 3").as_string(), "(1, 2, 3)") - @test_utils.require_version(minver="3.0") def test_func_signature_issue_185(self): code = textwrap.dedent( """ @@ -136,7 +135,6 @@ cdd = {k for k in b}\n\n""" ast = abuilder.string_build(code) self.assertMultiLineEqual(ast.as_string(), code) - @test_utils.require_version("3.0") def test_3k_as_string(self): """check as_string for python 3k syntax""" code = """print() @@ -401,20 +399,6 @@ class TryExceptFinallyNodeTest(_NodeTest): self.assertEqual(self.astroid.body[0].block_range(6), (6, 6)) -@unittest.skipIf(six.PY3, "Python 2 specific test.") -class TryExcept2xNodeTest(_NodeTest): - CODE = """ - try: - hello - except AttributeError, (retval, desc): - pass - """ - - def test_tuple_attribute(self): - handler = self.astroid.body[0].handlers[0] - self.assertIsInstance(handler.name, nodes.Tuple) - - class ImportNodeTest(resources.SysPathSetup, unittest.TestCase): def setUp(self): super(ImportNodeTest, self).setUp() @@ -580,7 +564,6 @@ class NameNodeTest(unittest.TestCase): class AnnAssignNodeTest(unittest.TestCase): - @test_utils.require_version(minver="3.6") def test_primitive(self): code = textwrap.dedent( """ @@ -594,7 +577,6 @@ class AnnAssignNodeTest(unittest.TestCase): self.assertEqual(assign.value.value, 5) self.assertEqual(assign.simple, 1) - @test_utils.require_version(minver="3.6") def test_primitive_without_initial_value(self): code = textwrap.dedent( """ @@ -607,7 +589,6 @@ class AnnAssignNodeTest(unittest.TestCase): self.assertEqual(assign.annotation.name, "str") self.assertEqual(assign.value, None) - @test_utils.require_version(minver="3.6") def test_complex(self): code = textwrap.dedent( """ @@ -620,7 +601,6 @@ class AnnAssignNodeTest(unittest.TestCase): self.assertIsInstance(assign.annotation, astroid.Subscript) self.assertIsInstance(assign.value, astroid.Dict) - @test_utils.require_version(minver="3.6") def test_as_string(self): code = textwrap.dedent( """ @@ -654,7 +634,6 @@ class ArgumentsNodeTC(unittest.TestCase): "(no line number on function args)" ) - @test_utils.require_version(minver="3.0") def test_kwoargs(self): ast = builder.parse( """ @@ -862,7 +841,6 @@ class AliasesTest(unittest.TestCase): self.assertIsInstance(module.body[6].value, nodes.GeneratorExp) -@test_utils.require_version("3.5") class Python35AsyncTest(unittest.TestCase): def test_async_await_keywords(self): async_def, async_for, async_with, await_node = builder.extract_node( @@ -962,13 +940,11 @@ class ContextTest(unittest.TestCase): with self.assertRaises(exceptions.AstroidSyntaxError): builder.extract_node("(1, ) = 3") - @test_utils.require_version(minver="3.5") def test_starred_load(self): node = builder.extract_node("a = *b") starred = node.value self.assertIs(starred.ctx, astroid.Load) - @test_utils.require_version(minver="3.0") def test_starred_store(self): node = builder.extract_node("a, *b = 1, 2") starred = node.targets[0].elts[1] @@ -1213,7 +1189,6 @@ def test_is_generator_for_yield_assignments(): class AsyncGeneratorTest: - @test_utils.require_version(minver="3.6") def test_async_generator(self): node = astroid.extract_node( """ @@ -1231,7 +1206,6 @@ class AsyncGeneratorTest: assert inferred.pytype() == "builtins.async_generator" assert inferred.display_type() == "AsyncGenerator" - @test_utils.require_version(maxver="3.5") def test_async_generator_is_generator_on_older_python(self): node = astroid.extract_node( """ diff --git a/tests/unittest_object_model.py b/tests/unittest_object_model.py index 5301a992..7311bff8 100644 --- a/tests/unittest_object_model.py +++ b/tests/unittest_object_model.py @@ -431,7 +431,6 @@ class FunctionModelTest(unittest.TestCase): for ast_node in ast_nodes[7:9]: self.assertIs(next(ast_node.infer()), astroid.Uninferable) - @test_utils.require_version(minver="3.0") def test_empty_return_annotation(self): ast_node = builder.extract_node( """ @@ -443,7 +442,6 @@ class FunctionModelTest(unittest.TestCase): self.assertIsInstance(annotations, astroid.Dict) self.assertEqual(len(annotations.items), 0) - @test_utils.require_version(minver="3.0") def test_builtin_dunder_init_does_not_crash_when_accessing_annotations(self): ast_node = builder.extract_node( """ @@ -457,7 +455,6 @@ class FunctionModelTest(unittest.TestCase): self.assertIsInstance(inferred, astroid.Dict) self.assertEqual(len(inferred.items), 0) - @test_utils.require_version(minver="3.0") def test_annotations_kwdefaults(self): ast_node = builder.extract_node( """ diff --git a/tests/unittest_objects.py b/tests/unittest_objects.py index a9de6eb2..b46134ed 100644 --- a/tests/unittest_objects.py +++ b/tests/unittest_objects.py @@ -14,7 +14,6 @@ from astroid import builder from astroid import exceptions from astroid import nodes from astroid import objects -from astroid import test_utils class ObjectsTest(unittest.TestCase): @@ -97,7 +96,6 @@ class SuperTests(unittest.TestCase): self.assertIsInstance(second, bases.Instance) self.assertEqual(second.qname(), "%s.super" % bases.BUILTINS) - @test_utils.require_version(minver="3.0") def test_no_arguments_super(self): ast_nodes = builder.extract_node( """ diff --git a/tests/unittest_protocols.py b/tests/unittest_protocols.py index 4f9bfbfc..e4c58d4d 100644 --- a/tests/unittest_protocols.py +++ b/tests/unittest_protocols.py @@ -18,7 +18,6 @@ import sys import astroid from astroid import extract_node -from astroid.test_utils import require_version from astroid import InferenceError from astroid import nodes from astroid import util @@ -67,7 +66,6 @@ class ProtocolTests(unittest.TestCase): for2_assnode = next(assign_stmts[1].nodes_of_class(AssignName)) self.assertRaises(InferenceError, list, for2_assnode.assigned_stmts()) - @require_version(minver="3.0") def test_assigned_stmts_starred_for(self): assign_stmts = extract_node( """ @@ -101,7 +99,6 @@ class ProtocolTests(unittest.TestCase): starred = next(assign_stmt.nodes_of_class(Starred)) self.assertRaises(InferenceError, list, starred.assigned_stmts()) - @require_version(minver="3.0") def test_assigned_stmts_starred_assnames(self): self._helper_starred_expected_const("a, *b = (1, 2, 3, 4) #@", [2, 3, 4]) self._helper_starred_expected_const("*a, b = (1, 2, 3) #@", [1, 2]) @@ -110,7 +107,6 @@ class ProtocolTests(unittest.TestCase): self._helper_starred_expected_const("*b, a = (1, 2) #@", [1]) self._helper_starred_expected_const("[*b] = (1, 2) #@", [1, 2]) - @require_version(minver="3.0") def test_assigned_stmts_starred_yes(self): # Not something iterable and known self._helper_starred_expected("a, *b = range(3) #@", util.Uninferable) @@ -128,7 +124,6 @@ class ProtocolTests(unittest.TestCase): "a, (*b, c), d = (1, (2, 3, 4), 5) #@", util.Uninferable ) - @require_version(minver="3.0") def test_assign_stmts_starred_fails(self): # Too many starred self._helper_starred_inference_error("a, *b, *c = (1, 2, 3) #@") @@ -159,7 +154,6 @@ class ProtocolTests(unittest.TestCase): assigned = list(simple_mul_assnode_2.assigned_stmts()) self.assertNameNodesEqual(["c"], assigned) - @require_version(minver="3.6") def test_assigned_stmts_annassignments(self): annassign_stmts = extract_node( """ diff --git a/tests/unittest_python3.py b/tests/unittest_python3.py index db2d233a..7b784427 100644 --- a/tests/unittest_python3.py +++ b/tests/unittest_python3.py @@ -27,7 +27,6 @@ class Python3TC(unittest.TestCase): def setUpClass(cls): cls.builder = AstroidBuilder() - @require_version("3.4") def test_starred_notation(self): astroid = self.builder.string_build("*a, b = [1, 2, 3]", "test", "test") @@ -36,7 +35,6 @@ class Python3TC(unittest.TestCase): self.assertTrue(isinstance(node.assign_type(), Assign)) - @require_version("3.4") def test_yield_from(self): body = dedent( """ @@ -53,7 +51,6 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(yieldfrom_stmt.value, YieldFrom) self.assertEqual(yieldfrom_stmt.as_string(), "yield from iter([1, 2])") - @require_version("3.4") def test_yield_from_is_generator(self): body = dedent( """ @@ -66,7 +63,6 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(func, FunctionDef) self.assertTrue(func.is_generator()) - @require_version("3.4") def test_yield_from_as_string(self): body = dedent( """ @@ -81,7 +77,6 @@ class Python3TC(unittest.TestCase): # metaclass tests - @require_version("3.4") def test_simple_metaclass(self): astroid = self.builder.string_build("class Test(metaclass=type): pass") klass = astroid.body[0] @@ -90,13 +85,11 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(metaclass, ClassDef) self.assertEqual(metaclass.name, "type") - @require_version("3.4") def test_metaclass_error(self): astroid = self.builder.string_build("class Test(metaclass=typ): pass") klass = astroid.body[0] self.assertFalse(klass.metaclass()) - @require_version("3.4") def test_metaclass_imported(self): astroid = self.builder.string_build( dedent( @@ -111,7 +104,6 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(metaclass, ClassDef) self.assertEqual(metaclass.name, "ABCMeta") - @require_version("3.4") def test_metaclass_multiple_keywords(self): astroid = self.builder.string_build( "class Test(magic=None, metaclass=type): pass" @@ -122,7 +114,6 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(metaclass, ClassDef) self.assertEqual(metaclass.name, "type") - @require_version("3.4") def test_as_string(self): body = dedent( """ @@ -136,7 +127,6 @@ class Python3TC(unittest.TestCase): klass.as_string(), "\n\nclass Test(metaclass=ABCMeta):\n pass\n" ) - @require_version("3.4") def test_old_syntax_works(self): astroid = self.builder.string_build( dedent( @@ -151,7 +141,6 @@ class Python3TC(unittest.TestCase): metaclass = klass.metaclass() self.assertIsNone(metaclass) - @require_version("3.4") def test_metaclass_yes_leak(self): astroid = self.builder.string_build( dedent( @@ -166,7 +155,6 @@ class Python3TC(unittest.TestCase): klass = astroid["Meta"] self.assertIsNone(klass.metaclass()) - @require_version("3.4") def test_parent_metaclass(self): astroid = self.builder.string_build( dedent( @@ -183,7 +171,6 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(metaclass, ClassDef) self.assertEqual(metaclass.name, "ABCMeta") - @require_version("3.4") def test_metaclass_ancestors(self): astroid = self.builder.string_build( dedent( @@ -212,7 +199,6 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(meta, ClassDef) self.assertEqual(meta.name, metaclass) - @require_version("3.4") def test_annotation_support(self): astroid = self.builder.string_build( dedent( @@ -255,7 +241,6 @@ class Python3TC(unittest.TestCase): self.assertEqual(func.args.annotations[1].name, "str") self.assertIsNone(func.returns) - @require_version("3.4") def test_kwonlyargs_annotations_supper(self): node = self.builder.string_build( dedent( @@ -276,7 +261,6 @@ class Python3TC(unittest.TestCase): self.assertIsNone(arguments.kwonlyargs_annotations[3]) self.assertIsNone(arguments.kwonlyargs_annotations[4]) - @require_version("3.4") def test_annotation_as_string(self): code1 = dedent( """ @@ -292,7 +276,6 @@ class Python3TC(unittest.TestCase): func = extract_node(code) self.assertEqual(func.as_string(), code) - @require_version("3.5") def test_unpacking_in_dicts(self): code = "{'x': 1, **{'y': 2}}" node = extract_node(code) @@ -301,13 +284,11 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(keys[0], nodes.Const) self.assertIsInstance(keys[1], nodes.DictUnpack) - @require_version("3.5") def test_nested_unpacking_in_dicts(self): code = "{'x': 1, **{'y': 2, **{'z': 3}}}" node = extract_node(code) self.assertEqual(node.as_string(), code) - @require_version("3.5") def test_unpacking_in_dict_getitem(self): node = extract_node("{1:2, **{2:3, 3:4}, **{5: 6}}") for key, expected in ((1, 2), (2, 3), (3, 4), (5, 6)): @@ -315,13 +296,11 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(value, nodes.Const) self.assertEqual(value.value, expected) - @require_version("3.6") def test_format_string(self): code = "f'{greetings} {person}'" node = extract_node(code) self.assertEqual(node.as_string(), code) - @require_version("3.6") def test_underscores_in_numeral_literal(self): pairs = [("10_1000", 101000), ("10_000_000", 10000000), ("0x_FF_FF", 65535)] for value, expected in pairs: @@ -330,7 +309,6 @@ class Python3TC(unittest.TestCase): self.assertIsInstance(inferred, nodes.Const) self.assertEqual(inferred.value, expected) - @require_version("3.6") def test_async_comprehensions(self): async_comprehensions = [ extract_node( @@ -379,7 +357,6 @@ class Python3TC(unittest.TestCase): node = extract_node(comp) self.assertTrue(node.generators[0].is_async) - @require_version("3.6") def test_async_comprehensions_as_string(self): func_bodies = [ "return [i async for i in aiter() if condition(i)]", diff --git a/tests/unittest_raw_building.py b/tests/unittest_raw_building.py index 160c88d7..9a284e73 100644 --- a/tests/unittest_raw_building.py +++ b/tests/unittest_raw_building.py @@ -21,7 +21,6 @@ from astroid.raw_building import ( build_function, build_from_import, ) -from astroid import test_utils class RawBuildingTC(unittest.TestCase): @@ -69,7 +68,6 @@ class RawBuildingTC(unittest.TestCase): self.assertEqual(len(names), len(node.names)) @unittest.skipIf(platform.python_implementation() == "PyPy", "Only affects CPython") - @test_utils.require_version(minver="3.0") def test_io_is__io(self): # _io module calls itself io. This leads # to cyclic dependencies when astroid tries to resolve diff --git a/tests/unittest_regrtest.py b/tests/unittest_regrtest.py index 1444da30..582e5072 100644 --- a/tests/unittest_regrtest.py +++ b/tests/unittest_regrtest.py @@ -22,7 +22,6 @@ from astroid.builder import AstroidBuilder, extract_node from astroid import exceptions from astroid.raw_building import build_module from astroid.manager import AstroidManager -from astroid.test_utils import require_version from astroid import transforms from . import resources @@ -100,7 +99,6 @@ multiply([1, 2], [3, 4]) inferred = callfunc.inferred() self.assertEqual(len(inferred), 1) - @require_version("3.0") def test_nameconstant(self): # used to fail for Python 3.4 builder = AstroidBuilder() diff --git a/tests/unittest_scoped_nodes.py b/tests/unittest_scoped_nodes.py index b28605e6..ba11f79c 100644 --- a/tests/unittest_scoped_nodes.py +++ b/tests/unittest_scoped_nodes.py @@ -54,6 +54,13 @@ from astroid.bases import BUILTINS, Instance, BoundMethod, UnboundMethod, Genera from astroid import test_utils from . import resources +try: + import six # pylint: disable=unused-import + + HAS_SIX = True +except ImportError: + HAS_SIX = False + def _test_dict_interface(self, node, test_attr): self.assertIs(node[test_attr], node[test_attr]) @@ -335,7 +342,6 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase): func = self.module["four_args"] self.assertEqual(func.args.format_args(), "a, b, c, d") - @test_utils.require_version("3.0") def test_format_args_keyword_only_args(self): node = ( builder.parse( @@ -596,7 +602,6 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase): self.assertIsInstance(inferred, nodes.Const) self.assertEqual(inferred.value, 42) - @test_utils.require_version(minver="3.0") def test_return_annotation_is_not_the_last(self): func = builder.extract_node( """ @@ -610,7 +615,6 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase): self.assertIsInstance(last_child, nodes.Return) self.assertEqual(func.tolineno, 5) - @test_utils.require_version(minver="3.6") def test_method_init_subclass(self): klass = builder.extract_node( """ @@ -623,7 +627,6 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase): self.assertEqual([n.name for n in method.args.args], ["cls"]) self.assertEqual(method.type, "classmethod") - @test_utils.require_version(minver="3.0") def test_dunder_class_local_to_method(self): node = builder.extract_node( """ @@ -636,7 +639,6 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase): self.assertIsInstance(inferred, nodes.ClassDef) self.assertEqual(inferred.name, "MyClass") - @test_utils.require_version(minver="3.0") def test_dunder_class_local_to_function(self): node = builder.extract_node( """ @@ -647,7 +649,6 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase): with self.assertRaises(NameInferenceError): next(node.infer()) - @test_utils.require_version(minver="3.0") def test_dunder_class_local_to_classmethod(self): node = builder.extract_node( """ @@ -1092,6 +1093,7 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): for klass in ast_nodes: self.assertEqual(None, klass.metaclass()) + @unittest.skipUnless(HAS_SIX, "These tests require the six library") def test_metaclass_generator_hack(self): klass = builder.extract_node( """ @@ -1104,14 +1106,12 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): self.assertEqual(["object"], [base.name for base in klass.ancestors()]) self.assertEqual("type", klass.metaclass().name) - def test_using_six_add_metaclass(self): + def test_add_metaclass(self): klass = builder.extract_node( """ - import six import abc - @six.add_metaclass(abc.ABCMeta) - class WithMeta(object): + class WithMeta(object, metaclass=abc.ABCMeta): pass """ ) @@ -1120,6 +1120,7 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): self.assertIsInstance(metaclass, scoped_nodes.ClassDef) self.assertIn(metaclass.qname(), ("abc.ABCMeta", "_py_abc.ABCMeta")) + @unittest.skipUnless(HAS_SIX, "These tests require the six library") def test_using_invalid_six_add_metaclass_call(self): klass = builder.extract_node( """ @@ -1272,6 +1273,7 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): def assertEqualMro(self, klass, expected_mro): self.assertEqual([member.name for member in klass.mro()], expected_mro) + @unittest.skipUnless(HAS_SIX, "These tests require the six library") def test_with_metaclass_mro(self): astroid = builder.parse( """ @@ -1499,13 +1501,10 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): def test_metaclass_lookup_inference_errors(self): module = builder.parse( """ - import six - class Metaclass(type): foo = lala - @six.add_metaclass(Metaclass) - class B(object): pass + class B(object, metaclass=Metaclass): pass """ ) cls = module["B"] @@ -1514,8 +1513,6 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): def test_metaclass_lookup(self): module = builder.parse( """ - import six - class Metaclass(type): foo = 42 @classmethod @@ -1530,8 +1527,7 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): def static(): pass - @six.add_metaclass(Metaclass) - class A(object): + class A(object, metaclass=Metaclass): pass """ ) @@ -1751,7 +1747,6 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase): parent = bind.scope() self.assertEqual(len(parent.extra_decorators), 0) - @test_utils.require_version(minver="3.0") def test_class_keywords(self): data = """ class TestKlass(object, metaclass=TestMetaKlass, @@ -1,5 +1,5 @@ [tox] -envlist = py35, py36, py37, py38, py39, pypy, pylint +envlist = py{36,37,38,39}, py{36,37,38,39}-six, pylint skip_missing_interpreters = true [testenv:pylint] @@ -18,13 +18,12 @@ deps = ; we have a brain for nose ; we use pytest for tests nose - py35,py36,py37,py38,py39: numpy - py35,py36,py37,py38,py39: attr - py35,py36,py37,py38,py39: typed_ast>=1.4.0,<1.5 + py{36,37,38,39}: numpy + py{36,37,38,39}: attrs + py{36,37,38,39}: typed_ast>=1.4.0,<1.5 pytest - python-dateutil - pypy: singledispatch - six~=1.12 + !py{36,37,38,39}-six: python-dateutil + six: six wrapt>=1.11,<1.13 coverage<5 |