summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-08-31 22:15:29 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-09-01 08:27:04 +0200
commit5f96098d658fd9c1b59c5f1675033485e1b3bad0 (patch)
treecfb6d8f4d46f7aa05c73b6cc10cabde3c7eae5de
parentca9eddc137936d1ffe83ec78d051f1b23f7c27b1 (diff)
downloadpylint-git-5f96098d658fd9c1b59c5f1675033485e1b3bad0.tar.gz
Remove the python3 porting mode from the codebase
It's possible to use the python3 porting checker from an older pylint version. But it's not evolving anymore and was costing resource to maintain.
-rw-r--r--ChangeLog3
-rw-r--r--doc/faq.rst4
-rw-r--r--doc/whatsnew/2.11.rst5
-rw-r--r--examples/pylintrc73
-rw-r--r--pylint/checkers/python3.py1432
-rw-r--r--pylint/lint/pylinter.py36
-rw-r--r--pylint/lint/run.py14
-rw-r--r--pylint/message/message_handler_mix_in.py3
-rw-r--r--tests/checkers/unittest_python3.py1178
-rw-r--r--tests/functional/a/abstract/abstract_abc_methods.py2
-rw-r--r--tests/functional/a/access/access_attr_before_def_false_positive.py2
-rw-r--r--tests/functional/a/access/access_to__name__.py2
-rw-r--r--tests/functional/a/access/access_to_protected_members.py2
-rw-r--r--tests/functional/a/arguments.py2
-rw-r--r--tests/functional/a/assign/assigning_non_slot.py2
-rw-r--r--tests/functional/b/bad_reversed_sequence.py2
-rw-r--r--tests/functional/b/base_init_vars.py4
-rw-r--r--tests/functional/c/cellvar_escaping_loop.py2
-rw-r--r--tests/functional/c/confidence_filter.rc2
-rw-r--r--tests/functional/d/defined_and_used_on_same_line.py2
-rw-r--r--tests/functional/d/dotted_ancestor.py3
-rw-r--r--tests/functional/d/dotted_ancestor.txt2
-rw-r--r--tests/functional/g/generated_members.rc2
-rw-r--r--tests/functional/i/import_error.py2
-rw-r--r--tests/functional/i/import_itself.py2
-rw-r--r--tests/functional/i/inherit_non_class.py2
-rw-r--r--tests/functional/i/invalid/e/invalid_exceptions_caught.py2
-rw-r--r--tests/functional/i/invalid/invalid_name.py2
-rw-r--r--tests/functional/l/len_checks.py2
-rw-r--r--tests/functional/l/logging_format_interpolation.py2
-rw-r--r--tests/functional/m/member/member_checks.py2
-rw-r--r--tests/functional/m/metaclass_attr_access.py5
-rw-r--r--tests/functional/m/method_hidden.py2
-rw-r--r--tests/functional/n/name/name_styles.py2
-rw-r--r--tests/functional/n/name/names_in__all__.py2
-rw-r--r--tests/functional/n/new_style_class_py_30.py2
-rw-r--r--tests/functional/n/no/no_name_in_module.py2
-rw-r--r--tests/functional/n/non/non_init_parent_called.py2
-rw-r--r--tests/functional/n/nonlocal_without_binding.py2
-rw-r--r--tests/functional/s/slots_checks.py2
-rw-r--r--tests/functional/s/string/string_formatting.py2
-rw-r--r--tests/functional/s/string/string_formatting_error.py2
-rw-r--r--tests/functional/s/string/string_log_formatting.py10
-rw-r--r--tests/functional/s/super/super_checks.py2
-rw-r--r--tests/functional/u/unpacking_non_sequence.py2
-rw-r--r--tests/functional/u/unused/unused_argument.py2
-rw-r--r--tests/functional/u/unused/unused_import.py2
-rw-r--r--tests/functional/u/unused/unused_name_from_wilcard_import.py2
-rw-r--r--tests/functional/w/wildcard_import.py2
-rw-r--r--tests/input/func_3k_removed_stuff_py_30.py2
-rw-r--r--tests/input/func_w0332_py_30.py4
-rw-r--r--tests/input/func_w0401.py2
-rw-r--r--tests/input/func_w0401_disabled.py2
-rw-r--r--tests/input/func_w0401_disabled_in_func.py2
-rw-r--r--tests/input/func_w0401_package/all_the_things.py2
-rw-r--r--tests/input/func_w0401_package/thing2.py2
-rw-r--r--tests/input/no_absolute_import.py5
-rw-r--r--tests/input/w0401_cycle.py2
-rw-r--r--tests/lint/unittest_lint.py13
-rw-r--r--tests/regrtest_data/func_block_disable_msg.py2
-rw-r--r--tests/regrtest_data/py3k-disabled.rc2
-rw-r--r--tests/regrtest_data/py3k_error_flag.py11
-rw-r--r--tests/regrtest_data/py3k_errors_and_warnings.py19
-rw-r--r--tests/test_self.py23
64 files changed, 67 insertions, 2868 deletions
diff --git a/ChangeLog b/ChangeLog
index aed43aa9f..754392a27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,9 @@ Release date: TBA
..
Put new features here and also in 'doc/whatsnew/2.11.rst'
+* The python3 porting mode checker and it's ``py3k`` option were removed. You can still find it in older pylint
+ versions.
+
* Added new extension ``SetMembershipChecker`` with ``use-set-for-membership`` check:
Emitted when using an in-place defined ``list`` or ``tuple`` to do a membership test. ``sets`` are better optimized for that.
diff --git a/doc/faq.rst b/doc/faq.rst
index 02e252457..479d3c052 100644
--- a/doc/faq.rst
+++ b/doc/faq.rst
@@ -192,9 +192,7 @@ tricks like: ::
pylint does have some messages disabled by default, either because
they are prone to false positives or that they are opinionated enough
-for not being included as default messages. But most of the disabled
-messages are from the Python 3 porting checker, which is disabled by
-default. It needs special activation with the ``--py3k`` flag.
+for not being included as default messages.
You can see the plugin you need to explicitly `load in the technical reference`_
diff --git a/doc/whatsnew/2.11.rst b/doc/whatsnew/2.11.rst
index e91199fb0..8a9161c71 100644
--- a/doc/whatsnew/2.11.rst
+++ b/doc/whatsnew/2.11.rst
@@ -16,6 +16,11 @@ New checkers
Closes #3592
+Removed checkers
+================
+
+* The python3 porting mode checker and it's ``py3k`` option were removed. You can still find it in older pylint
+ versions.
Extensions
==========
diff --git a/examples/pylintrc b/examples/pylintrc
index 8a50a5833..0bfe95939 100644
--- a/examples/pylintrc
+++ b/examples/pylintrc
@@ -69,17 +69,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
-disable=print-statement,
- parameter-unpacking,
- unpacking-in-except,
- old-raise-syntax,
- backtick,
- long-suffix,
- old-ne-operator,
- old-octal-literal,
- import-star-module-level,
- non-ascii-bytes-literal,
- raw-checker-failed,
+disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
@@ -87,67 +77,6 @@ disable=print-statement,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
- apply-builtin,
- basestring-builtin,
- buffer-builtin,
- cmp-builtin,
- coerce-builtin,
- execfile-builtin,
- file-builtin,
- long-builtin,
- raw_input-builtin,
- reduce-builtin,
- standarderror-builtin,
- unicode-builtin,
- xrange-builtin,
- coerce-method,
- delslice-method,
- getslice-method,
- setslice-method,
- no-absolute-import,
- old-division,
- dict-iter-method,
- dict-view-method,
- next-method-called,
- metaclass-assignment,
- indexing-exception,
- raising-string,
- reload-builtin,
- oct-method,
- hex-method,
- nonzero-method,
- cmp-method,
- input-builtin,
- round-builtin,
- intern-builtin,
- unichr-builtin,
- map-builtin-not-iterating,
- zip-builtin-not-iterating,
- range-builtin-not-iterating,
- filter-builtin-not-iterating,
- using-cmp-argument,
- eq-without-hash,
- div-method,
- idiv-method,
- rdiv-method,
- exception-message-attribute,
- invalid-str-codec,
- sys-max-int,
- bad-python3-import,
- deprecated-string-function,
- deprecated-str-translate-call,
- deprecated-itertools-function,
- deprecated-types-field,
- next-method-defined,
- dict-items-not-iterating,
- dict-keys-not-iterating,
- dict-values-not-iterating,
- deprecated-operator-function,
- deprecated-urllib-function,
- xreadlines-attribute,
- deprecated-sys-function,
- exception-escape,
- comprehension-escape
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py
deleted file mode 100644
index 71c5e98a8..000000000
--- a/pylint/checkers/python3.py
+++ /dev/null
@@ -1,1432 +0,0 @@
-# Copyright (c) 2014-2020 Claudiu Popa <pcmanticore@gmail.com>
-# Copyright (c) 2014-2015 Brett Cannon <brett@python.org>
-# Copyright (c) 2015 Simu Toni <simutoni@gmail.com>
-# Copyright (c) 2015 Pavel Roskin <proski@gnu.org>
-# Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
-# Copyright (c) 2015 Cosmin Poieana <cmin@ropython.org>
-# Copyright (c) 2015 Viorel Stirbu <viorels@gmail.com>
-# Copyright (c) 2016, 2018 Jakub Wilk <jwilk@jwilk.net>
-# Copyright (c) 2016-2017 Roy Williams <roy.williams.iii@gmail.com>
-# Copyright (c) 2016 Roy Williams <rwilliams@lyft.com>
-# Copyright (c) 2016 Łukasz Rogalski <rogalski.91@gmail.com>
-# Copyright (c) 2016 Erik <erik.eriksson@yahoo.com>
-# Copyright (c) 2017, 2020 hippo91 <guillaume.peillex@gmail.com>
-# Copyright (c) 2017-2018 Ville Skyttä <ville.skytta@iki.fi>
-# Copyright (c) 2017 Daniel Miller <millerdev@gmail.com>
-# Copyright (c) 2017 ahirnish <ahirnish@gmail.com>
-# Copyright (c) 2018-2020 Anthony Sottile <asottile@umich.edu>
-# Copyright (c) 2018 sbagan <pnlbagan@gmail.com>
-# Copyright (c) 2018 Lucas Cimon <lucas.cimon@gmail.com>
-# Copyright (c) 2018 Aivar Annamaa <aivarannamaa@users.noreply.github.com>
-# Copyright (c) 2018 ssolanki <sushobhitsolanki@gmail.com>
-# Copyright (c) 2018 Sushobhit <31987769+sushobhit27@users.noreply.github.com>
-# Copyright (c) 2018 Ashley Whetter <ashley@awhetter.co.uk>
-# Copyright (c) 2018 gaurikholkar <f2013002@goa.bits-pilani.ac.in>
-# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
-# Copyright (c) 2019 Nick Drozd <nicholasdrozd@gmail.com>
-# Copyright (c) 2019 Hugues Bruant <hugues.bruant@affirm.com>
-# Copyright (c) 2019 Gabriel R Sezefredo <gabriel@sezefredo.com.br>
-# Copyright (c) 2019 Hugo van Kemenade <hugovk@users.noreply.github.com>
-# Copyright (c) 2019 bluesheeptoken <louis.fruleux1@gmail.com>
-# Copyright (c) 2020 Peter Kolbus <peter.kolbus@gmail.com>
-# Copyright (c) 2020 谭九鼎 <109224573@qq.com>
-# Copyright (c) 2020 Federico Bond <federicobond@gmail.com>
-# Copyright (c) 2020 Athos Ribeiro <athoscr@fedoraproject.org>
-# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
-# Copyright (c) 2021 bot <bot@noreply.github.com>
-# Copyright (c) 2021 Tiago Honorato <tiagohonorato1@gmail.com>
-# Copyright (c) 2021 tiagohonorato <61059243+tiagohonorato@users.noreply.github.com>
-# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
-
-"""Check Python 2 code for Python 2/3 source-compatible issues."""
-import itertools
-import re
-import tokenize
-from collections import namedtuple
-
-import astroid
-from astroid import nodes
-
-from pylint import checkers, interfaces
-from pylint.checkers import utils
-from pylint.checkers.utils import find_try_except_wrapper_node, node_ignores_exception
-from pylint.constants import WarningScope
-from pylint.interfaces import INFERENCE, INFERENCE_FAILURE
-
-_ZERO = re.compile("^0+$")
-
-
-def _is_old_octal(literal):
- if _ZERO.match(literal):
- return False
- if re.match(r"0\d+", literal):
- try:
- int(literal, 8)
- except ValueError:
- return False
- return True
- return None
-
-
-def _inferred_value_is_dict(value):
- if isinstance(value, nodes.Dict):
- return True
- return isinstance(value, astroid.Instance) and "dict" in value.basenames
-
-
-def _infer_if_relevant_attr(node, relevant_attrs):
- return node.expr.infer() if node.attrname in relevant_attrs else []
-
-
-def _is_builtin(node):
- return getattr(node, "name", None) in ("__builtin__", "builtins")
-
-
-_ACCEPTS_ITERATOR = {
- "iter",
- "list",
- "tuple",
- "sorted",
- "set",
- "sum",
- "any",
- "all",
- "enumerate",
- "dict",
- "filter",
- "reversed",
- "max",
- "min",
- "frozenset",
- "OrderedDict",
- "zip",
- "map",
-}
-ATTRIBUTES_ACCEPTS_ITERATOR = {"join", "from_iterable"}
-_BUILTIN_METHOD_ACCEPTS_ITERATOR = {
- "builtins.list.extend",
- "builtins.dict.update",
- "builtins.set.update",
-}
-DICT_METHODS = {"items", "keys", "values"}
-
-
-def _in_iterating_context(node):
- """Check if the node is being used as an iterator.
-
- Definition is taken from lib2to3.fixer_util.in_special_context().
- """
- parent = node.parent
- # Since a call can't be the loop variant we only need to know if the node's
- # parent is a 'for' loop to know it's being used as the iterator for the
- # loop.
- if isinstance(parent, nodes.For):
- return True
- # Need to make sure the use of the node is in the iterator part of the
- # comprehension.
- if isinstance(parent, nodes.Comprehension):
- if parent.iter == node:
- return True
- # Various built-ins can take in an iterable or list and lead to the same
- # value.
- elif isinstance(parent, nodes.Call):
- if isinstance(parent.func, nodes.Name):
- if parent.func.name in _ACCEPTS_ITERATOR:
- return True
- elif isinstance(parent.func, nodes.Attribute):
- if parent.func.attrname in ATTRIBUTES_ACCEPTS_ITERATOR:
- return True
-
- inferred = utils.safe_infer(parent.func)
- if inferred:
- if inferred.qname() in _BUILTIN_METHOD_ACCEPTS_ITERATOR:
- return True
- root = inferred.root()
- if root and root.name == "itertools":
- return True
- # If the call is in an unpacking, there's no need to warn,
- # since it can be considered iterating.
- elif isinstance(parent, nodes.Assign) and isinstance(
- parent.targets[0], (nodes.List, nodes.Tuple)
- ):
- if len(parent.targets[0].elts) > 1:
- return True
- # If the call is in a containment check, we consider that to
- # be an iterating context
- elif (
- isinstance(parent, nodes.Compare)
- and len(parent.ops) == 1
- and parent.ops[0][0] in ["in", "not in"]
- ):
- return True
- # Also if it's an `yield from`, that's fair
- elif isinstance(parent, nodes.YieldFrom):
- return True
- if isinstance(parent, nodes.Starred):
- return True
- return False
-
-
-def _is_conditional_import(node):
- """Checks if an import node is in the context of a conditional."""
- parent = node.parent
- return isinstance(
- parent, (nodes.TryExcept, nodes.ExceptHandler, nodes.If, nodes.IfExp)
- )
-
-
-Branch = namedtuple("Branch", ["node", "is_py2_only"])
-
-
-class Python3Checker(checkers.BaseChecker):
-
- __implements__ = interfaces.IAstroidChecker
- enabled = False
- name = "python3"
-
- msgs = {
- # Errors for what will syntactically break in Python 3, warnings for
- # everything else.
- "E1601": (
- "print statement used",
- "print-statement",
- "Used when a print statement is used "
- "(`print` is a function in Python 3)",
- ),
- "E1602": (
- "Parameter unpacking specified",
- "parameter-unpacking",
- "Used when parameter unpacking is specified for a function"
- "(Python 3 doesn't allow it)",
- ),
- "E1603": (
- "Implicit unpacking of exceptions is not supported in Python 3",
- "unpacking-in-except",
- "Python3 will not allow implicit unpacking of "
- "exceptions in except clauses. "
- "See https://www.python.org/dev/peps/pep-3110/",
- {"old_names": [("W0712", "old-unpacking-in-except")]},
- ),
- "E1604": (
- "Use raise ErrorClass(args) instead of raise ErrorClass, args.",
- "old-raise-syntax",
- "Used when the alternate raise syntax "
- "'raise foo, bar' is used "
- "instead of 'raise foo(bar)'.",
- {"old_names": [("W0121", "old-old-raise-syntax")]},
- ),
- "E1605": (
- "Use of the `` operator",
- "backtick",
- 'Used when the deprecated "``" (backtick) operator is used '
- "instead of the str() function.",
- {"scope": WarningScope.NODE, "old_names": [("W0333", "old-backtick")]},
- ),
- "E1609": (
- "Import * only allowed at module level",
- "import-star-module-level",
- "Used when the import star syntax is used somewhere "
- "else than the module level.",
- {"maxversion": (3, 0)},
- ),
- "W1601": (
- "apply built-in referenced",
- "apply-builtin",
- "Used when the apply built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1602": (
- "basestring built-in referenced",
- "basestring-builtin",
- "Used when the basestring built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1603": (
- "buffer built-in referenced",
- "buffer-builtin",
- "Used when the buffer built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1604": (
- "cmp built-in referenced",
- "cmp-builtin",
- "Used when the cmp built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1605": (
- "coerce built-in referenced",
- "coerce-builtin",
- "Used when the coerce built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1606": (
- "execfile built-in referenced",
- "execfile-builtin",
- "Used when the execfile built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1607": (
- "file built-in referenced",
- "file-builtin",
- "Used when the file built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1608": (
- "long built-in referenced",
- "long-builtin",
- "Used when the long built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1609": (
- "raw_input built-in referenced",
- "raw_input-builtin",
- "Used when the raw_input built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1610": (
- "reduce built-in referenced",
- "reduce-builtin",
- "Used when the reduce built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1611": (
- "StandardError built-in referenced",
- "standarderror-builtin",
- "Used when the StandardError built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1612": (
- "unicode built-in referenced",
- "unicode-builtin",
- "Used when the unicode built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1613": (
- "xrange built-in referenced",
- "xrange-builtin",
- "Used when the xrange built-in function is referenced "
- "(missing from Python 3)",
- ),
- "W1614": (
- "__coerce__ method defined",
- "coerce-method",
- "Used when a __coerce__ method is defined "
- "(method is not used by Python 3)",
- ),
- "W1615": (
- "__delslice__ method defined",
- "delslice-method",
- "Used when a __delslice__ method is defined "
- "(method is not used by Python 3)",
- ),
- "W1616": (
- "__getslice__ method defined",
- "getslice-method",
- "Used when a __getslice__ method is defined "
- "(method is not used by Python 3)",
- ),
- "W1617": (
- "__setslice__ method defined",
- "setslice-method",
- "Used when a __setslice__ method is defined "
- "(method is not used by Python 3)",
- ),
- "W1618": (
- "import missing `from __future__ import absolute_import`",
- "no-absolute-import",
- "Used when an import is not accompanied by "
- "``from __future__ import absolute_import`` "
- "(default behaviour in Python 3)",
- ),
- "W1619": (
- "division w/o __future__ statement",
- "old-division",
- "Used for non-floor division w/o a float literal or "
- "``from __future__ import division`` "
- "(Python 3 returns a float for int division unconditionally)",
- ),
- "W1620": (
- "Calling a dict.iter*() method",
- "dict-iter-method",
- "Used for calls to dict.iterkeys(), itervalues() or iteritems() "
- "(Python 3 lacks these methods)",
- ),
- "W1621": (
- "Calling a dict.view*() method",
- "dict-view-method",
- "Used for calls to dict.viewkeys(), viewvalues() or viewitems() "
- "(Python 3 lacks these methods)",
- ),
- "W1622": (
- "Called a next() method on an object",
- "next-method-called",
- "Used when an object's next() method is called "
- "(Python 3 uses the next() built-in function)",
- ),
- "W1623": (
- "Assigning to a class's __metaclass__ attribute",
- "metaclass-assignment",
- "Used when a metaclass is specified by assigning to __metaclass__ "
- "(Python 3 specifies the metaclass as a class statement argument)",
- ),
- "W1624": (
- "Indexing exceptions will not work on Python 3",
- "indexing-exception",
- "Indexing exceptions will not work on Python 3. Use "
- "`exception.args[index]` instead.",
- {"old_names": [("W0713", "old-indexing-exception")]},
- ),
- "W1625": (
- "Raising a string exception",
- "raising-string",
- "Used when a string exception is raised. This will not "
- "work on Python 3.",
- {"old_names": [("W0701", "old-raising-string")]},
- ),
- "W1626": (
- "reload built-in referenced",
- "reload-builtin",
- "Used when the reload built-in function is referenced "
- "(missing from Python 3). You can use instead imp.reload "
- "or importlib.reload.",
- ),
- "W1627": (
- "__oct__ method defined",
- "oct-method",
- "Used when an __oct__ method is defined "
- "(method is not used by Python 3)",
- ),
- "W1628": (
- "__hex__ method defined",
- "hex-method",
- "Used when a __hex__ method is defined (method is not used by Python 3)",
- ),
- "W1629": (
- "__nonzero__ method defined",
- "nonzero-method",
- "Used when a __nonzero__ method is defined "
- "(method is not used by Python 3)",
- ),
- "W1630": (
- "__cmp__ method defined",
- "cmp-method",
- "Used when a __cmp__ method is defined (method is not used by Python 3)",
- ),
- # 'W1631': replaced by W1636
- "W1632": (
- "input built-in referenced",
- "input-builtin",
- "Used when the input built-in is referenced "
- "(backwards-incompatible semantics in Python 3)",
- ),
- "W1633": (
- "round built-in referenced",
- "round-builtin",
- "Used when the round built-in is referenced "
- "(backwards-incompatible semantics in Python 3)",
- ),
- "W1634": (
- "intern built-in referenced",
- "intern-builtin",
- "Used when the intern built-in is referenced "
- "(Moved to sys.intern in Python 3)",
- ),
- "W1635": (
- "unichr built-in referenced",
- "unichr-builtin",
- "Used when the unichr built-in is referenced (Use chr in Python 3)",
- ),
- "W1636": (
- "map built-in referenced when not iterating",
- "map-builtin-not-iterating",
- "Used when the map built-in is referenced in a non-iterating "
- "context (returns an iterator in Python 3)",
- {"old_names": [("W1631", "implicit-map-evaluation")]},
- ),
- "W1637": (
- "zip built-in referenced when not iterating",
- "zip-builtin-not-iterating",
- "Used when the zip built-in is referenced in a non-iterating "
- "context (returns an iterator in Python 3)",
- ),
- "W1638": (
- "range built-in referenced when not iterating",
- "range-builtin-not-iterating",
- "Used when the range built-in is referenced in a non-iterating "
- "context (returns a range in Python 3)",
- ),
- "W1639": (
- "filter built-in referenced when not iterating",
- "filter-builtin-not-iterating",
- "Used when the filter built-in is referenced in a non-iterating "
- "context (returns an iterator in Python 3)",
- ),
- "W1640": (
- "Using the cmp argument for list.sort / sorted",
- "using-cmp-argument",
- "Using the cmp argument for list.sort or the sorted "
- "builtin should be avoided, since it was removed in "
- "Python 3. Using either `key` or `functools.cmp_to_key` "
- "should be preferred.",
- ),
- "W1641": (
- "Implementing __eq__ without also implementing __hash__",
- "eq-without-hash",
- "Used when a class implements __eq__ but not __hash__. In Python 2, objects "
- "get object.__hash__ as the default implementation, in Python 3 objects get "
- "None as their default __hash__ implementation if they also implement __eq__.",
- ),
- "W1642": (
- "__div__ method defined",
- "div-method",
- "Used when a __div__ method is defined. Using `__truediv__` and setting"
- "__div__ = __truediv__ should be preferred."
- "(method is not used by Python 3)",
- ),
- "W1643": (
- "__idiv__ method defined",
- "idiv-method",
- "Used when an __idiv__ method is defined. Using `__itruediv__` and setting"
- "__idiv__ = __itruediv__ should be preferred."
- "(method is not used by Python 3)",
- ),
- "W1644": (
- "__rdiv__ method defined",
- "rdiv-method",
- "Used when a __rdiv__ method is defined. Using `__rtruediv__` and setting"
- "__rdiv__ = __rtruediv__ should be preferred."
- "(method is not used by Python 3)",
- ),
- "W1645": (
- "Exception.message removed in Python 3",
- "exception-message-attribute",
- "Used when the message attribute is accessed on an Exception. Use "
- "str(exception) instead.",
- ),
- "W1646": (
- "non-text encoding used in str.decode",
- "invalid-str-codec",
- "Used when using str.encode or str.decode with a non-text encoding. Use "
- "codecs module to handle arbitrary codecs.",
- ),
- "W1647": (
- "sys.maxint removed in Python 3",
- "sys-max-int",
- "Used when accessing sys.maxint. Use sys.maxsize instead.",
- ),
- "W1648": (
- "Module moved in Python 3",
- "bad-python3-import",
- "Used when importing a module that no longer exists in Python 3.",
- ),
- "W1649": (
- "Accessing a deprecated function on the string module",
- "deprecated-string-function",
- "Used when accessing a string function that has been deprecated in Python 3.",
- ),
- "W1650": (
- "Using str.translate with deprecated deletechars parameters",
- "deprecated-str-translate-call",
- "Used when using the deprecated deletechars parameters from str.translate. Use "
- "re.sub to remove the desired characters ",
- ),
- "W1651": (
- "Accessing a deprecated function on the itertools module",
- "deprecated-itertools-function",
- "Used when accessing a function on itertools that has been removed in Python 3.",
- ),
- "W1652": (
- "Accessing a deprecated fields on the types module",
- "deprecated-types-field",
- "Used when accessing a field on types that has been removed in Python 3.",
- ),
- "W1653": (
- "next method defined",
- "next-method-defined",
- "Used when a next method is defined that would be an iterator in Python 2 but "
- "is treated as a normal function in Python 3.",
- ),
- "W1654": (
- "dict.items referenced when not iterating",
- "dict-items-not-iterating",
- "Used when dict.items is referenced in a non-iterating "
- "context (returns an iterator in Python 3)",
- ),
- "W1655": (
- "dict.keys referenced when not iterating",
- "dict-keys-not-iterating",
- "Used when dict.keys is referenced in a non-iterating "
- "context (returns an iterator in Python 3)",
- ),
- "W1656": (
- "dict.values referenced when not iterating",
- "dict-values-not-iterating",
- "Used when dict.values is referenced in a non-iterating "
- "context (returns an iterator in Python 3)",
- ),
- "W1657": (
- "Accessing a removed attribute on the operator module",
- "deprecated-operator-function",
- "Used when accessing a field on operator module that has been "
- "removed in Python 3.",
- ),
- "W1658": (
- "Accessing a removed attribute on the urllib module",
- "deprecated-urllib-function",
- "Used when accessing a field on urllib module that has been "
- "removed or moved in Python 3.",
- ),
- "W1659": (
- "Accessing a removed xreadlines attribute",
- "xreadlines-attribute",
- "Used when accessing the xreadlines() function on a file stream, "
- "removed in Python 3.",
- ),
- "W1660": (
- "Accessing a removed attribute on the sys module",
- "deprecated-sys-function",
- "Used when accessing a field on sys module that has been "
- "removed in Python 3.",
- ),
- "W1661": (
- "Using an exception object that was bound by an except handler",
- "exception-escape",
- "Emitted when using an exception, that was bound in an except "
- "handler, outside of the except handler. On Python 3 these "
- "exceptions will be deleted once they get out "
- "of the except handler.",
- ),
- "W1662": (
- "Using a variable that was bound inside a comprehension",
- "comprehension-escape",
- "Emitted when using a variable, that was bound in a comprehension "
- "handler, outside of the comprehension itself. On Python 3 these "
- "variables will be deleted outside of the "
- "comprehension.",
- ),
- }
-
- _bad_builtins = frozenset(
- [
- "apply",
- "basestring",
- "buffer",
- "cmp",
- "coerce",
- "execfile",
- "file",
- "input", # Not missing, but incompatible semantics
- "intern",
- "long",
- "raw_input",
- "reduce",
- "round", # Not missing, but incompatible semantics
- "StandardError",
- "unichr",
- "unicode",
- "xrange",
- "reload",
- ]
- )
-
- _unused_magic_methods = frozenset(
- [
- "__coerce__",
- "__delslice__",
- "__getslice__",
- "__setslice__",
- "__oct__",
- "__hex__",
- "__nonzero__",
- "__cmp__",
- "__div__",
- "__idiv__",
- "__rdiv__",
- ]
- )
-
- _invalid_encodings = frozenset(
- [
- "base64_codec",
- "base64",
- "base_64",
- "bz2_codec",
- "bz2",
- "hex_codec",
- "hex",
- "quopri_codec",
- "quopri",
- "quotedprintable",
- "quoted_printable",
- "uu_codec",
- "uu",
- "zlib_codec",
- "zlib",
- "zip",
- "rot13",
- "rot_13",
- ]
- )
-
- _bad_python3_module_map = {
- "sys-max-int": {"sys": frozenset(["maxint"])},
- "deprecated-itertools-function": {
- "itertools": frozenset(
- ["izip", "ifilter", "imap", "izip_longest", "ifilterfalse"]
- )
- },
- "deprecated-types-field": {
- "types": frozenset(
- [
- "EllipsisType",
- "XRangeType",
- "ComplexType",
- "StringType",
- "TypeType",
- "LongType",
- "UnicodeType",
- "ClassType",
- "BufferType",
- "StringTypes",
- "NotImplementedType",
- "NoneType",
- "InstanceType",
- "FloatType",
- "SliceType",
- "UnboundMethodType",
- "ObjectType",
- "IntType",
- "TupleType",
- "ListType",
- "DictType",
- "FileType",
- "DictionaryType",
- "BooleanType",
- "DictProxyType",
- ]
- )
- },
- "bad-python3-import": frozenset(
- [
- "anydbm",
- "BaseHTTPServer",
- "__builtin__",
- "CGIHTTPServer",
- "ConfigParser",
- "copy_reg",
- "cPickle",
- "cStringIO",
- "Cookie",
- "cookielib",
- "dbhash",
- "dumbdbm",
- "dumbdb",
- "Dialog",
- "DocXMLRPCServer",
- "FileDialog",
- "FixTk",
- "gdbm",
- "htmlentitydefs",
- "HTMLParser",
- "httplib",
- "markupbase",
- "Queue",
- "repr",
- "robotparser",
- "ScrolledText",
- "SimpleDialog",
- "SimpleHTTPServer",
- "SimpleXMLRPCServer",
- "StringIO",
- "dummy_thread",
- "SocketServer",
- "test.test_support",
- "Tkinter",
- "Tix",
- "Tkconstants",
- "tkColorChooser",
- "tkCommonDialog",
- "Tkdnd",
- "tkFileDialog",
- "tkFont",
- "tkMessageBox",
- "tkSimpleDialog",
- "UserList",
- "UserString",
- "whichdb",
- "_winreg",
- "xmlrpclib",
- "audiodev",
- "Bastion",
- "bsddb185",
- "bsddb3",
- "Canvas",
- "cfmfile",
- "cl",
- "commands",
- "compiler",
- "dircache",
- "dl",
- "exception",
- "fpformat",
- "htmllib",
- "ihooks",
- "imageop",
- "imputil",
- "linuxaudiodev",
- "md5",
- "mhlib",
- "mimetools",
- "MimeWriter",
- "mimify",
- "multifile",
- "mutex",
- "new",
- "popen2",
- "posixfile",
- "pure",
- "rexec",
- "rfc822",
- "sets",
- "sha",
- "sgmllib",
- "sre",
- "stringold",
- "sunaudio",
- "sv",
- "test.testall",
- "thread",
- "timing",
- "toaiff",
- "user",
- "urllib2",
- "urlparse",
- ]
- ),
- "deprecated-string-function": {
- "string": frozenset(
- [
- "maketrans",
- "atof",
- "atoi",
- "atol",
- "capitalize",
- "expandtabs",
- "find",
- "rfind",
- "index",
- "rindex",
- "count",
- "lower",
- "letters",
- "split",
- "rsplit",
- "splitfields",
- "join",
- "joinfields",
- "lstrip",
- "rstrip",
- "strip",
- "swapcase",
- "translate",
- "upper",
- "ljust",
- "rjust",
- "center",
- "zfill",
- "replace",
- "lowercase",
- "letters",
- "uppercase",
- "atol_error",
- "atof_error",
- "atoi_error",
- "index_error",
- ]
- )
- },
- "deprecated-operator-function": {"operator": frozenset({"div"})},
- "deprecated-urllib-function": {
- "urllib": frozenset(
- {
- "addbase",
- "addclosehook",
- "addinfo",
- "addinfourl",
- "always_safe",
- "basejoin",
- "ftpcache",
- "ftperrors",
- "ftpwrapper",
- "getproxies",
- "getproxies_environment",
- "getproxies_macosx_sysconf",
- "main",
- "noheaders",
- "pathname2url",
- "proxy_bypass",
- "proxy_bypass_environment",
- "proxy_bypass_macosx_sysconf",
- "quote",
- "quote_plus",
- "reporthook",
- "splitattr",
- "splithost",
- "splitnport",
- "splitpasswd",
- "splitport",
- "splitquery",
- "splittag",
- "splittype",
- "splituser",
- "splitvalue",
- "unquote",
- "unquote_plus",
- "unwrap",
- "url2pathname",
- "urlcleanup",
- "urlencode",
- "urlopen",
- "urlretrieve",
- }
- )
- },
- "deprecated-sys-function": {"sys": frozenset({"exc_clear"})},
- }
-
- _deprecated_attrs = frozenset(
- itertools.chain.from_iterable(
- attr
- for module_map in _bad_python3_module_map.values()
- if isinstance(module_map, dict)
- for attr in module_map.values()
- )
- )
-
- _relevant_call_attrs = (
- DICT_METHODS | _deprecated_attrs | {"encode", "decode", "translate"}
- )
-
- _python_2_tests = frozenset(
- astroid.extract_node(x).repr_tree()
- for x in (
- "sys.version_info[0] == 2",
- "sys.version_info[0] < 3",
- "sys.version_info == (2, 7)",
- "sys.version_info <= (2, 7)",
- "sys.version_info < (3, 0)",
- )
- )
-
- def __init__(self, *args, **kwargs):
- self._future_division = False
- self._future_absolute_import = False
- self._modules_warned_about = set()
- self._branch_stack = []
- super().__init__(*args, **kwargs)
-
- # pylint: disable=keyword-arg-before-vararg, arguments-differ
- def add_message(self, msg_id, always_warn=False, *args, **kwargs):
- if always_warn or not (
- self._branch_stack and self._branch_stack[-1].is_py2_only
- ):
- super().add_message(msg_id, *args, **kwargs)
-
- def _is_py2_test(self, node):
- if isinstance(node.test, nodes.Attribute) and isinstance(
- node.test.expr, nodes.Name
- ):
- if node.test.expr.name == "six" and node.test.attrname == "PY2":
- return True
- elif (
- isinstance(node.test, nodes.Compare)
- and node.test.repr_tree() in self._python_2_tests
- ):
- return True
- return False
-
- def visit_if(self, node):
- self._branch_stack.append(Branch(node, self._is_py2_test(node)))
-
- def leave_if(self, node):
- new_node = self._branch_stack.pop().node
- assert new_node == node
-
- def visit_ifexp(self, node):
- self._branch_stack.append(Branch(node, self._is_py2_test(node)))
-
- def leave_ifexp(self, node):
- new_node = self._branch_stack.pop()
- assert new_node.node == node
-
- def visit_module(self, node): # pylint: disable=unused-argument
- """Clear checker state after previous module."""
- self._future_division = False
- self._future_absolute_import = False
-
- def visit_functiondef(self, node):
- if node.is_method():
- if node.name in self._unused_magic_methods:
- method_name = node.name
- if node.name.startswith("__"):
- method_name = node.name[2:-2]
- self.add_message(method_name + "-method", node=node)
- elif node.name == "next":
- # If there is a method named `next` declared, if it is invokable
- # with zero arguments then it implements the Iterator protocol.
- # This means if the method is an instance method or a
- # classmethod 1 argument should cause a failure, if it is a
- # staticmethod 0 arguments should cause a failure.
- failing_arg_count = 1
- if utils.decorated_with(node, ["builtins.staticmethod"]):
- failing_arg_count = 0
- if len(node.args.args) == failing_arg_count:
- self.add_message("next-method-defined", node=node)
-
- @utils.check_messages("parameter-unpacking")
- def visit_arguments(self, node):
- for arg in node.args:
- if isinstance(arg, nodes.Tuple):
- self.add_message("parameter-unpacking", node=arg)
-
- @utils.check_messages("comprehension-escape")
- def visit_listcomp(self, node):
- names = {
- generator.target.name
- for generator in node.generators
- if isinstance(generator.target, nodes.AssignName)
- }
- scope = node.parent.scope()
- scope_names = scope.nodes_of_class(nodes.Name, skip_klass=nodes.FunctionDef)
- has_redefined_assign_name = any(
- assign_name
- for assign_name in scope.nodes_of_class(
- nodes.AssignName, skip_klass=nodes.FunctionDef
- )
- if assign_name.name in names and assign_name.lineno > node.lineno
- )
- if has_redefined_assign_name:
- return
-
- emitted_for_names = set()
- scope_names = list(scope_names)
- for scope_name in scope_names:
- if (
- scope_name.name not in names
- or scope_name.lineno <= node.lineno
- or scope_name.name in emitted_for_names
- or scope_name.scope() == node
- ):
- continue
-
- emitted_for_names.add(scope_name.name)
- self.add_message("comprehension-escape", node=scope_name)
-
- def visit_name(self, node):
- """Detect when a "bad" built-in is referenced."""
- found_node, _ = node.lookup(node.name)
- if not _is_builtin(found_node):
- return
- if node.name not in self._bad_builtins:
- return
- if node_ignores_exception(node) or isinstance(
- find_try_except_wrapper_node(node), nodes.ExceptHandler
- ):
- return
-
- message = node.name.lower() + "-builtin"
- self.add_message(message, node=node)
-
- @utils.check_messages("print-statement")
- def visit_print(self, node):
- self.add_message("print-statement", node=node, always_warn=True)
-
- def _warn_if_deprecated(self, node, module, attributes, report_on_modules=True):
- for message, module_map in self._bad_python3_module_map.items():
- if module in module_map and module not in self._modules_warned_about:
- if isinstance(module_map, frozenset):
- if report_on_modules:
- self._modules_warned_about.add(module)
- self.add_message(message, node=node)
- elif attributes and module_map[module].intersection(attributes):
- self.add_message(message, node=node)
-
- def visit_importfrom(self, node):
- if node.modname == "__future__":
- for name, _ in node.names:
- if name == "division":
- self._future_division = True
- elif name == "absolute_import":
- self._future_absolute_import = True
- else:
- if not self._future_absolute_import:
- if self.linter.is_message_enabled("no-absolute-import"):
- self.add_message("no-absolute-import", node=node)
- self._future_absolute_import = True
- if not _is_conditional_import(node) and not node.level:
- self._warn_if_deprecated(node, node.modname, {x[0] for x in node.names})
-
- if node.names[0][0] == "*":
- if self.linter.is_message_enabled("import-star-module-level"):
- if not isinstance(node.scope(), nodes.Module):
- self.add_message("import-star-module-level", node=node)
-
- def visit_import(self, node):
- if not self._future_absolute_import:
- if self.linter.is_message_enabled("no-absolute-import"):
- self.add_message("no-absolute-import", node=node)
- self._future_absolute_import = True
- if not _is_conditional_import(node):
- for name, _ in node.names:
- self._warn_if_deprecated(node, name, None)
-
- @utils.check_messages("metaclass-assignment")
- def visit_classdef(self, node):
- if "__metaclass__" in node.locals:
- self.add_message("metaclass-assignment", node=node)
- locals_and_methods = set(node.locals).union(x.name for x in node.mymethods())
- if "__eq__" in locals_and_methods and "__hash__" not in locals_and_methods:
- self.add_message("eq-without-hash", node=node)
-
- @utils.check_messages("old-division")
- def visit_binop(self, node):
- if not self._future_division and node.op == "/":
- for arg in (node.left, node.right):
- inferred = utils.safe_infer(arg)
- # If we can infer the object and that object is not an int, bail out.
- if inferred and not (
- (
- isinstance(inferred, nodes.Const)
- and isinstance(inferred.value, int)
- )
- or (
- isinstance(inferred, astroid.Instance)
- and inferred.name == "int"
- )
- ):
- break
- else:
- self.add_message("old-division", node=node)
-
- def _check_cmp_argument(self, node):
- # Check that the `cmp` argument is used
- kwargs = []
- if isinstance(node.func, nodes.Attribute) and node.func.attrname == "sort":
- inferred = utils.safe_infer(node.func.expr)
- if not inferred:
- return
-
- builtins_list = "builtins.list"
- if isinstance(inferred, nodes.List) or inferred.qname() == builtins_list:
- kwargs = node.keywords
-
- elif isinstance(node.func, nodes.Name) and node.func.name == "sorted":
- inferred = utils.safe_infer(node.func)
- if not inferred:
- return
-
- builtins_sorted = "builtins.sorted"
- if inferred.qname() == builtins_sorted:
- kwargs = node.keywords
-
- for kwarg in kwargs or []:
- if kwarg.arg == "cmp":
- self.add_message("using-cmp-argument", node=node)
- return
-
- @staticmethod
- def _is_constant_string_or_name(node):
- if isinstance(node, nodes.Const):
- return isinstance(node.value, str)
- return isinstance(node, nodes.Name)
-
- @staticmethod
- def _is_none(node):
- return isinstance(node, nodes.Const) and node.value is None
-
- @staticmethod
- def _has_only_n_positional_args(node, number_of_args):
- return len(node.args) == number_of_args and all(node.args) and not node.keywords
-
- @staticmethod
- def _could_be_string(inferred_types):
- confidence = INFERENCE if inferred_types else INFERENCE_FAILURE
- for inferred_type in inferred_types:
- if inferred_type is astroid.Uninferable:
- confidence = INFERENCE_FAILURE
- elif not (
- isinstance(inferred_type, nodes.Const)
- and isinstance(inferred_type.value, str)
- ):
- return None
- return confidence
-
- def visit_call(self, node):
- self._check_cmp_argument(node)
-
- if isinstance(node.func, nodes.Attribute):
- inferred_types = set()
-
- try:
- for inferred_receiver in _infer_if_relevant_attr(
- node.func, self._relevant_call_attrs
- ):
- if inferred_receiver is astroid.Uninferable:
- continue
- inferred_types.add(inferred_receiver)
- if isinstance(inferred_receiver, nodes.Module):
- self._warn_if_deprecated(
- node,
- inferred_receiver.name,
- {node.func.attrname},
- report_on_modules=False,
- )
- if (
- _inferred_value_is_dict(inferred_receiver)
- and node.func.attrname in DICT_METHODS
- ):
- if not _in_iterating_context(node):
- checker = f"dict-{node.func.attrname}-not-iterating"
- self.add_message(checker, node=node)
- except astroid.InferenceError:
- pass
- if node.args:
- is_str_confidence = self._could_be_string(inferred_types)
- if is_str_confidence:
- if (
- node.func.attrname in ("encode", "decode")
- and len(node.args) >= 1
- and node.args[0]
- ):
- first_arg = node.args[0]
- self._validate_encoding(first_arg, node)
- if (
- node.func.attrname == "translate"
- and self._has_only_n_positional_args(node, 2)
- and self._is_none(node.args[0])
- and self._is_constant_string_or_name(node.args[1])
- ):
- # The above statement looking for calls of the form:
- #
- # foo.translate(None, 'abc123')
- #
- # or
- #
- # foo.translate(None, some_variable)
- #
- # This check is somewhat broad and _may_ have some false positives, but
- # after checking several large codebases it did not have any false
- # positives while finding several real issues. This call pattern seems
- # rare enough that the trade off is worth it.
- self.add_message(
- "deprecated-str-translate-call",
- node=node,
- confidence=is_str_confidence,
- )
- return
- if node.keywords:
- return
- if node.func.attrname == "next":
- self.add_message("next-method-called", node=node)
- elif node.func.attrname in ("iterkeys", "itervalues", "iteritems"):
- self.add_message("dict-iter-method", node=node)
- elif node.func.attrname in ("viewkeys", "viewvalues", "viewitems"):
- self.add_message("dict-view-method", node=node)
- elif isinstance(node.func, nodes.Name):
- found_node = node.func.lookup(node.func.name)[0]
- if _is_builtin(found_node):
- if node.func.name in ("filter", "map", "range", "zip"):
- if not _in_iterating_context(node):
- checker = f"{node.func.name}-builtin-not-iterating"
- self.add_message(checker, node=node)
- elif node.func.name == "open" and node.keywords:
- kwargs = node.keywords
- for kwarg in kwargs or []:
- if kwarg.arg == "encoding":
- self._validate_encoding(kwarg.value, node)
- break
-
- def _validate_encoding(self, encoding, node):
- if isinstance(encoding, nodes.Const):
- value = encoding.value
- if value in self._invalid_encodings:
- self.add_message("invalid-str-codec", node=node)
-
- @utils.check_messages("indexing-exception")
- def visit_subscript(self, node):
- """Look for indexing exceptions."""
- try:
- for inferred in node.value.infer():
- if not isinstance(inferred, astroid.Instance):
- continue
- if utils.inherit_from_std_ex(inferred):
- self.add_message("indexing-exception", node=node)
- except astroid.InferenceError:
- return
-
- def visit_assignattr(self, node):
- if isinstance(node.assign_type(), nodes.AugAssign):
- self.visit_attribute(node)
-
- def visit_delattr(self, node):
- self.visit_attribute(node)
-
- @utils.check_messages("exception-message-attribute", "xreadlines-attribute")
- def visit_attribute(self, node):
- """Look for removed attributes"""
- if node.attrname == "xreadlines":
- self.add_message("xreadlines-attribute", node=node)
- return
-
- exception_message = "message"
- try:
- for inferred in _infer_if_relevant_attr(
- node, self._deprecated_attrs | {exception_message}
- ):
- if isinstance(inferred, astroid.Instance) and utils.inherit_from_std_ex(
- inferred
- ):
- if node.attrname == exception_message:
-
- # Exceptions with .message clearly defined are an exception
- if exception_message in inferred.instance_attrs:
- continue
- self.add_message("exception-message-attribute", node=node)
- if isinstance(inferred, nodes.Module):
- self._warn_if_deprecated(
- node, inferred.name, {node.attrname}, report_on_modules=False
- )
- except astroid.InferenceError:
- return
-
- @utils.check_messages("unpacking-in-except", "comprehension-escape")
- def visit_excepthandler(self, node):
- """Visit an except handler block and check for exception unpacking."""
-
- def _is_used_in_except_block(node, block):
- current = node
- while current and current is not block:
- current = current.parent
- return current is not None
-
- if isinstance(node.name, (nodes.Tuple, nodes.List)):
- self.add_message("unpacking-in-except", node=node)
- return
-
- if not node.name:
- return
-
- # Find any names
- scope = node.parent.scope()
- scope_names = scope.nodes_of_class(nodes.Name, skip_klass=nodes.FunctionDef)
- scope_names = list(scope_names)
- potential_leaked_names = [
- scope_name
- for scope_name in scope_names
- if scope_name.name == node.name.name
- and scope_name.lineno > node.lineno
- and not _is_used_in_except_block(scope_name, node)
- ]
- reassignments_for_same_name = {
- assign_name.lineno
- for assign_name in scope.nodes_of_class(
- nodes.AssignName, skip_klass=nodes.FunctionDef
- )
- if assign_name.name == node.name.name
- }
- for leaked_name in potential_leaked_names:
- if any(
- node.lineno < elem < leaked_name.lineno
- for elem in reassignments_for_same_name
- ):
- continue
- self.add_message("exception-escape", node=leaked_name)
-
- @utils.check_messages("backtick")
- def visit_repr(self, node):
- self.add_message("backtick", node=node)
-
- @utils.check_messages("raising-string", "old-raise-syntax")
- def visit_raise(self, node):
- """Visit a raise statement and check for raising
- strings or old-raise-syntax.
- """
-
- # Ignore empty raise.
- if node.exc is None:
- return
- expr = node.exc
- if self._check_raise_value(node, expr):
- return
- try:
- value = next(astroid.unpack_infer(expr))
- except astroid.InferenceError:
- return
- self._check_raise_value(node, value)
-
- def _check_raise_value(self, node, expr):
- if isinstance(expr, nodes.Const):
- value = expr.value
- if isinstance(value, str):
- self.add_message("raising-string", node=node)
- return True
- return None
-
-
-class Python3TokenChecker(checkers.BaseTokenChecker):
- __implements__ = interfaces.ITokenChecker
- name = "python3"
- enabled = False
-
- msgs = {
- "E1606": (
- "Use of long suffix",
- "long-suffix",
- 'Used when "l" or "L" is used to mark a long integer. '
- "This will not work in Python 3, since `int` and `long` "
- "types have merged.",
- {"maxversion": (3, 0)},
- ),
- "E1607": (
- "Use of the <> operator",
- "old-ne-operator",
- 'Used when the deprecated "<>" operator is used instead '
- 'of "!=". This is removed in Python 3.',
- {"maxversion": (3, 0), "old_names": [("W0331", "old-old-ne-operator")]},
- ),
- "E1608": (
- "Use of old octal literal",
- "old-octal-literal",
- "Used when encountering the old octal syntax, "
- "removed in Python 3. To use the new syntax, "
- "prepend 0o on the number.",
- {"maxversion": (3, 0)},
- ),
- "E1610": (
- "Non-ascii bytes literals not supported in 3.x",
- "non-ascii-bytes-literal",
- "Used when non-ascii bytes literals are found in a program. "
- "They are no longer supported in Python 3.",
- {"maxversion": (3, 0)},
- ),
- }
-
- def process_tokens(self, tokens):
- for idx, (tok_type, token, start, _, _) in enumerate(tokens):
- if tok_type == tokenize.NUMBER:
- if token.lower().endswith("l"):
- # This has a different semantic than lowercase-l-suffix.
- self.add_message("long-suffix", line=start[0])
- elif _is_old_octal(token):
- self.add_message("old-octal-literal", line=start[0])
- if tokens[idx][1] == "<>":
- self.add_message("old-ne-operator", line=tokens[idx][2][0])
- if tok_type == tokenize.STRING and token.startswith("b"):
- if any(elem for elem in token if ord(elem) > 127):
- self.add_message("non-ascii-bytes-literal", line=start[0])
-
-
-def register(linter):
- linter.register_checker(Python3Checker(linter))
- linter.register_checker(Python3TokenChecker(linter))
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 8582f7637..59276a50a 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -536,7 +536,6 @@ class PyLinter(
)
self.register_checker(self)
self._dynamic_plugins = set()
- self._python3_porting_mode = False
self._error_mode = False
self.load_provider_defaults()
if reporter:
@@ -755,45 +754,10 @@ class PyLinter(
self._error_mode = True
self.disable_noerror_messages()
self.disable("miscellaneous")
- if self._python3_porting_mode:
- self.disable("all")
- for msg_id in self._checker_messages("python3"):
- if msg_id.startswith("E"):
- self.enable(msg_id)
- config_parser = self.cfgfile_parser
- if config_parser.has_option("MESSAGES CONTROL", "disable"):
- value = config_parser.get("MESSAGES CONTROL", "disable")
- self.global_set_option("disable", value)
- else:
- self.disable("python3")
self.set_option("reports", False)
self.set_option("persistent", False)
self.set_option("score", False)
- def python3_porting_mode(self):
- """Disable all other checkers and enable Python 3 warnings."""
- self.disable("all")
- # re-enable some errors, or 'print', 'raise', 'async', 'await' will mistakenly lint fine
- self.enable("fatal") # F0001
- self.enable("astroid-error") # F0002
- self.enable("parse-error") # F0010
- self.enable("syntax-error") # E0001
- self.enable("python3")
- if self._error_mode:
- # The error mode was activated, using the -E flag.
- # So we'll need to enable only the errors from the
- # Python 3 porting checker.
- for msg_id in self._checker_messages("python3"):
- if msg_id.startswith("E"):
- self.enable(msg_id)
- else:
- self.disable(msg_id)
- config_parser = self.cfgfile_parser
- if config_parser.has_option("MESSAGES CONTROL", "disable"):
- value = config_parser.get("MESSAGES CONTROL", "disable")
- self.global_set_option("disable", value)
- self._python3_porting_mode = True
-
def list_messages_enabled(self):
emittable, non_emittable = self.msgs_store.find_emittable_messages()
enabled = []
diff --git a/pylint/lint/run.py b/pylint/lint/run.py
index ac4f586f4..d84ed2703 100644
--- a/pylint/lint/run.py
+++ b/pylint/lint/run.py
@@ -248,16 +248,6 @@ group are mutually exclusive.",
},
),
(
- "py3k",
- {
- "action": "callback",
- "callback": self.cb_python3_porting_mode,
- "help": "In Python 3 porting mode, all checkers will be "
- "disabled and only messages emitted by the porting "
- "checker will be displayed.",
- },
- ),
- (
"verbose",
{
"action": "callback",
@@ -469,9 +459,5 @@ group are mutually exclusive.",
print(check)
sys.exit(0)
- def cb_python3_porting_mode(self, *args, **kwargs):
- """Activate only the python3 porting checker."""
- self.linter.python3_porting_mode()
-
def cb_verbose_mode(self, *args, **kwargs):
self.verbose = True
diff --git a/pylint/message/message_handler_mix_in.py b/pylint/message/message_handler_mix_in.py
index c2dd4d0cb..00adfa5d9 100644
--- a/pylint/message/message_handler_mix_in.py
+++ b/pylint/message/message_handler_mix_in.py
@@ -94,9 +94,6 @@ class MessagesHandlerMixIn:
if msgid == "all":
for _msgid in MSG_TYPES:
self._set_msg_status(_msgid, enable, scope, line, ignore_unknown)
- if enable and not self._python3_porting_mode:
- # Don't activate the python 3 porting checker if it wasn't activated explicitly.
- self.disable("python3")
return
# msgid is a category?
diff --git a/tests/checkers/unittest_python3.py b/tests/checkers/unittest_python3.py
deleted file mode 100644
index 6dd78cd25..000000000
--- a/tests/checkers/unittest_python3.py
+++ /dev/null
@@ -1,1178 +0,0 @@
-# Copyright (c) 2014-2020 Claudiu Popa <pcmanticore@gmail.com>
-# Copyright (c) 2014-2015 Brett Cannon <brett@python.org>
-# Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
-# Copyright (c) 2015 Cosmin Poieana <cmin@ropython.org>
-# Copyright (c) 2015 Viorel Stirbu <viorels@gmail.com>
-# Copyright (c) 2016-2017 Roy Williams <roy.williams.iii@gmail.com>
-# Copyright (c) 2016 Roy Williams <rwilliams@lyft.com>
-# Copyright (c) 2016 Derek Gustafson <degustaf@gmail.com>
-# Copyright (c) 2017 Daniel Miller <millerdev@gmail.com>
-# Copyright (c) 2018-2020 Anthony Sottile <asottile@umich.edu>
-# Copyright (c) 2018 sbagan <pnlbagan@gmail.com>
-# Copyright (c) 2018 Aivar Annamaa <aivarannamaa@users.noreply.github.com>
-# Copyright (c) 2018 Ville Skyttä <ville.skytta@iki.fi>
-# Copyright (c) 2019-2021 Pierre Sassoulas <pierre.sassoulas@gmail.com>
-# Copyright (c) 2019 Gabriel R Sezefredo <gabriel@sezefredo.com.br>
-# Copyright (c) 2019 Hugo van Kemenade <hugovk@users.noreply.github.com>
-# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk>
-# Copyright (c) 2020 hippo91 <guillaume.peillex@gmail.com>
-# Copyright (c) 2020 Federico Bond <federicobond@gmail.com>
-# Copyright (c) 2020 Athos Ribeiro <athoscr@fedoraproject.org>
-# Copyright (c) 2021 Marc Mueller <30130371+cdce8p@users.noreply.github.com>
-# Copyright (c) 2021 Tiago Honorato <tiagohonorato1@gmail.com>
-# Copyright (c) 2021 tiagohonorato <61059243+tiagohonorato@users.noreply.github.com>
-# Copyright (c) 2021 David Gilman <davidgilman1@gmail.com>
-
-# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
-# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
-
-"""Tests for the python3 checkers."""
-
-# pylint: disable=too-many-public-methods,redefined-outer-name
-
-import astroid
-
-from pylint import testutils
-from pylint.checkers import python3 as checker
-from pylint.interfaces import INFERENCE, INFERENCE_FAILURE
-
-# TODO(cpopa): Port these to the functional test framework instead. pylint: disable=fixme
-
-
-class TestPython3Checker(testutils.CheckerTestCase):
-
- CHECKER_CLASS = checker.Python3Checker
-
- def check_bad_builtin(self, builtin_name):
- node = astroid.extract_node(builtin_name + " #@")
- message = builtin_name.lower() + "-builtin"
- with self.assertAddsMessages(testutils.Message(message, node=node)):
- self.checker.visit_name(node)
-
- def test_bad_builtins(self):
- builtins = [
- "apply",
- "buffer",
- "cmp",
- "coerce",
- "execfile",
- "file",
- "input",
- "intern",
- "long",
- "raw_input",
- "round",
- "reduce",
- "StandardError",
- "unichr",
- "unicode",
- "xrange",
- "reload",
- ]
- for builtin in builtins:
- self.check_bad_builtin(builtin)
-
- def as_iterable_in_for_loop_test(self, fxn):
- code = f"for x in {fxn}(): pass"
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def as_used_by_iterable_in_for_loop_test(self, fxn):
- checker = f"{fxn}-builtin-not-iterating"
- node = astroid.extract_node(
- f"""
- for x in (whatever(
- {fxn}() #@
- )):
- pass
- """
- )
- message = testutils.Message(checker, node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def as_iterable_in_genexp_test(self, fxn):
- code = f"x = (x for x in {fxn}())"
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def as_iterable_in_starred_context(self, fxn):
- code = f"x = test(*{fxn}())"
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def as_iterable_in_listcomp_test(self, fxn):
- code = f"x = [x for x in {fxn}(None, [1])]"
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def as_iterable_in_yield_from(self, fxn):
- code = f"yield from {fxn}()"
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def as_used_in_variant_in_genexp_test(self, fxn):
- checker = f"{fxn}-builtin-not-iterating"
- node = astroid.extract_node(
- f"""
- list(
- __({fxn}(x))
- for x in [1]
- )
- """
- )
- message = testutils.Message(checker, node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def as_used_in_variant_in_listcomp_test(self, fxn):
- checker = f"{fxn}-builtin-not-iterating"
- node = astroid.extract_node(
- f"""
- [
- __({fxn}(None, x))
- for x in [[1]]]
- """
- )
- message = testutils.Message(checker, node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def as_argument_to_callable_constructor_test(self, fxn, callable_fn):
- module = astroid.parse(f"x = {callable_fn}({fxn}())")
- with self.assertNoMessages():
- self.walk(module)
-
- def as_argument_to_materialized_filter(self, callable_fn):
- module = astroid.parse(f"list(filter(None, {callable_fn}()))")
- with self.assertNoMessages():
- self.walk(module)
-
- def as_argument_to_random_fxn_test(self, fxn):
- checker = f"{fxn}-builtin-not-iterating"
- node = astroid.extract_node(
- f"""
- y(
- {fxn}() #@
- )
- """
- )
- message = testutils.Message(checker, node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def as_argument_to_str_join_test(self, fxn):
- code = f"x = ''.join({fxn}())"
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def as_argument_to_itertools_functions(self, fxn):
- code = f"""
- from __future__ import absolute_import
- import itertools
- from itertools import product
- for i,j in product({fxn}(), repeat=2):
- pass
- for i,j in itertools.product({fxn}(), repeat=2):
- pass
- """
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def as_argument_to_zip_test(self, fxn):
- module = astroid.parse(f"list(zip({fxn}))")
- with self.assertNoMessages():
- self.walk(module)
-
- def as_argument_to_map_test(self, fxn):
- module = astroid.parse(f"list(map(__, {fxn}()))")
- with self.assertNoMessages():
- self.walk(module)
-
- def as_iterable_in_unpacking(self, fxn):
- node = astroid.extract_node(
- f"""
- a, b = __({fxn}())
- """
- )
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def as_assignment(self, fxn):
- checker = f"{fxn}-builtin-not-iterating"
- node = astroid.extract_node(
- f"""
- a = __({fxn}())
- """
- )
- message = testutils.Message(checker, node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def iterating_context_tests(self, fxn):
- """Helper for verifying a function isn't used as an iterator."""
- self.as_iterable_in_for_loop_test(fxn)
- self.as_used_by_iterable_in_for_loop_test(fxn)
- self.as_iterable_in_genexp_test(fxn)
- self.as_iterable_in_listcomp_test(fxn)
- self.as_used_in_variant_in_genexp_test(fxn)
- self.as_used_in_variant_in_listcomp_test(fxn)
- self.as_argument_to_random_fxn_test(fxn)
- self.as_argument_to_str_join_test(fxn)
- self.as_iterable_in_unpacking(fxn)
- self.as_assignment(fxn)
- self.as_argument_to_materialized_filter(fxn)
- self.as_iterable_in_yield_from(fxn)
- self.as_iterable_in_starred_context(fxn)
- self.as_argument_to_itertools_functions(fxn)
- self.as_argument_to_zip_test(fxn)
- self.as_argument_to_map_test(fxn)
- for func in (
- "iter",
- "list",
- "tuple",
- "sorted",
- "set",
- "sum",
- "any",
- "all",
- "enumerate",
- "dict",
- "OrderedDict",
- ):
- self.as_argument_to_callable_constructor_test(fxn, func)
-
- def test_dict_subclasses_methods_in_iterating_context(self):
- iterating, not_iterating = astroid.extract_node(
- """
- from __future__ import absolute_import
- from collections import defaultdict
- d = defaultdict(list)
- a, b = d.keys() #@
- x = d.keys() #@
- """
- )
-
- with self.assertNoMessages():
- self.checker.visit_call(iterating.value)
-
- message = testutils.Message("dict-keys-not-iterating", node=not_iterating.value)
- with self.assertAddsMessages(message):
- self.checker.visit_call(not_iterating.value)
-
- def test_dict_methods_in_iterating_context(self):
- iterating_code = [
- "for x in {}(): pass",
- "(x for x in {}())",
- "[x for x in {}()]",
- "iter({}())",
- "a, b = {}()",
- "max({}())",
- "min({}())",
- "3 in {}()",
- "3 not in {}()",
- "set().update({}())",
- "[].extend({}())",
- "{{}}.update({}())",
- """
- from __future__ import absolute_import
- from itertools import chain
- chain.from_iterable({}())
- """,
- ]
- non_iterating_code = ["x = __({}())", "__({}())[0]"]
-
- for method in ("keys", "items", "values"):
- dict_method = f"{{}}.{method}"
-
- for code in iterating_code:
- with_value = code.format(dict_method)
- module = astroid.parse(with_value)
- with self.assertNoMessages():
- self.walk(module)
-
- for code in non_iterating_code:
- with_value = code.format(dict_method)
- node = astroid.extract_node(with_value)
-
- checker = f"dict-{method}-not-iterating"
- message = testutils.Message(checker, node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_map_in_iterating_context(self):
- self.iterating_context_tests("map")
-
- def test_zip_in_iterating_context(self):
- self.iterating_context_tests("zip")
-
- def test_range_in_iterating_context(self):
- self.iterating_context_tests("range")
-
- def test_filter_in_iterating_context(self):
- self.iterating_context_tests("filter")
-
- def defined_method_test(self, method, warning):
- """Helper for verifying that a certain method is not defined."""
- node = astroid.extract_node(
- f"""
- class Foo(object):
- def __{method}__(self, other): #@
- pass"""
- )
- message = testutils.Message(warning, node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_functiondef(node)
-
- def test_delslice_method(self):
- self.defined_method_test("delslice", "delslice-method")
-
- def test_getslice_method(self):
- self.defined_method_test("getslice", "getslice-method")
-
- def test_setslice_method(self):
- self.defined_method_test("setslice", "setslice-method")
-
- def test_coerce_method(self):
- self.defined_method_test("coerce", "coerce-method")
-
- def test_oct_method(self):
- self.defined_method_test("oct", "oct-method")
-
- def test_hex_method(self):
- self.defined_method_test("hex", "hex-method")
-
- def test_nonzero_method(self):
- self.defined_method_test("nonzero", "nonzero-method")
-
- def test_cmp_method(self):
- self.defined_method_test("cmp", "cmp-method")
-
- def test_div_method(self):
- self.defined_method_test("div", "div-method")
-
- def test_idiv_method(self):
- self.defined_method_test("idiv", "idiv-method")
-
- def test_rdiv_method(self):
- self.defined_method_test("rdiv", "rdiv-method")
-
- def test_eq_and_hash_method(self):
- """Helper for verifying that a certain method is not defined."""
- node = astroid.extract_node(
- """
- class Foo(object): #@
- def __eq__(self, other):
- pass
- def __hash__(self):
- pass"""
- )
- with self.assertNoMessages():
- self.checker.visit_classdef(node)
-
- def test_eq_and_hash_is_none(self):
- """Helper for verifying that a certain method is not defined."""
- node = astroid.extract_node(
- """
- class Foo(object): #@
- def __eq__(self, other):
- pass
- __hash__ = None"""
- )
- with self.assertNoMessages():
- self.checker.visit_classdef(node)
-
- def test_eq_without_hash_method(self):
- """Helper for verifying that a certain method is not defined."""
- node = astroid.extract_node(
- """
- class Foo(object): #@
- def __eq__(self, other):
- pass"""
- )
- message = testutils.Message("eq-without-hash", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_classdef(node)
-
- def test_relative_import(self):
- node = astroid.extract_node("import string #@")
- message = testutils.Message("no-absolute-import", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_import(node)
- with self.assertNoMessages():
- # message should only be added once
- self.checker.visit_import(node)
-
- def test_relative_from_import(self):
- node = astroid.extract_node("from os import path #@")
- message = testutils.Message("no-absolute-import", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_importfrom(node)
- with self.assertNoMessages():
- # message should only be added once
- self.checker.visit_importfrom(node)
-
- def test_absolute_import(self):
- module_import = astroid.parse(
- "from __future__ import absolute_import; import os"
- )
- module_from = astroid.parse(
- "from __future__ import absolute_import; from os import path"
- )
- with self.assertNoMessages():
- for module in (module_import, module_from):
- self.walk(module)
-
- def test_import_star_module_level(self):
- node = astroid.extract_node(
- """
- def test():
- from lala import * #@
- """
- )
- absolute = testutils.Message("no-absolute-import", node=node)
- star = testutils.Message("import-star-module-level", node=node)
- with self.assertAddsMessages(absolute, star):
- self.checker.visit_importfrom(node)
-
- def test_division(self):
- nodes = astroid.extract_node(
- """\
- from _unknown import a, b
- 3 / 2 #@
- 3 / int(a) #@
- int(a) / 3 #@
- a / b #@
- """
- )
- for node in nodes:
- message = testutils.Message("old-division", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_binop(node)
-
- def test_division_with_future_statement(self):
- module = astroid.parse("from __future__ import division; 3 / 2")
- with self.assertNoMessages():
- self.walk(module)
-
- def test_floor_division(self):
- node = astroid.extract_node(" 3 // 2 #@")
- with self.assertNoMessages():
- self.checker.visit_binop(node)
-
- def test_division_by_float(self):
- nodes = astroid.extract_node(
- """\
- 3.0 / 2 #@
- 3 / 2.0 #@
- 3 / float(a) #@
- float(a) / 3 #@
- """
- )
- with self.assertNoMessages():
- for node in nodes:
- self.checker.visit_binop(node)
-
- def test_division_different_types(self):
- nodes = astroid.extract_node(
- """
- class A:
- pass
- A / 2 #@
- A() / 2 #@
- "a" / "a" #@
- class Path:
- def __div__(self, other):
- return 42
- Path() / 24 #@
- """
- )
- for node in nodes:
- with self.assertNoMessages():
- self.checker.visit_binop(node)
-
- def test_dict_iter_method(self):
- for meth in ("keys", "values", "items"):
- node = astroid.extract_node(f"x.iter{meth}() #@")
- message = testutils.Message("dict-iter-method", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_dict_iter_method_on_dict(self):
- nodes = astroid.extract_node(
- """
- from collections import defaultdict
- {}.iterkeys() #@
- defaultdict(list).iterkeys() #@
- class Someclass(dict):
- pass
- Someclass().iterkeys() #@
-
- # Emits even though we are not sure they are dicts
- x.iterkeys() #@
-
- def func(x):
- x.iterkeys() #@
- """
- )
- for node in nodes:
- message = testutils.Message("dict-iter-method", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_dict_not_iter_method(self):
- arg_node = astroid.extract_node("x.iterkeys(x) #@")
- stararg_node = astroid.extract_node("x.iterkeys(*x) #@")
- kwarg_node = astroid.extract_node("x.iterkeys(y=x) #@")
- with self.assertNoMessages():
- for node in (arg_node, stararg_node, kwarg_node):
- self.checker.visit_call(node)
-
- def test_dict_view_method(self):
- for meth in ("keys", "values", "items"):
- node = astroid.extract_node(f"x.view{meth}() #@")
- message = testutils.Message("dict-view-method", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_dict_viewkeys(self):
- nodes = astroid.extract_node(
- """
- from collections import defaultdict
- {}.viewkeys() #@
- defaultdict(list).viewkeys() #@
- class Someclass(dict):
- pass
- Someclass().viewkeys() #@
-
- # Emits even though they might not be dicts
- x.viewkeys() #@
-
- def func(x):
- x.viewkeys() #@
- """
- )
- for node in nodes:
- message = testutils.Message("dict-view-method", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_next_method(self):
- node = astroid.extract_node("x.next() #@")
- message = testutils.Message("next-method-called", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_not_next_method(self):
- arg_node = astroid.extract_node("x.next(x) #@")
- stararg_node = astroid.extract_node("x.next(*x) #@")
- kwarg_node = astroid.extract_node("x.next(y=x) #@")
- with self.assertNoMessages():
- for node in (arg_node, stararg_node, kwarg_node):
- self.checker.visit_call(node)
-
- def test_metaclass_assignment(self):
- node = astroid.extract_node(
- """
- class Foo(object): #@
- __metaclass__ = type"""
- )
- message = testutils.Message("metaclass-assignment", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_classdef(node)
-
- def test_metaclass_global_assignment(self):
- module = astroid.parse("__metaclass__ = type")
- with self.assertNoMessages():
- self.walk(module)
-
- def test_xreadlines_attribute(self):
- node = astroid.extract_node(
- """
- f.xreadlines #@
- """
- )
- message = testutils.Message("xreadlines-attribute", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_attribute(node)
-
- def test_exception_message_attribute(self):
- node = astroid.extract_node(
- """
- try:
- raise Exception("test")
- except Exception as e:
- e.message #@
- """
- )
- message = testutils.Message("exception-message-attribute", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_attribute(node)
-
- def test_normal_message_attribute(self):
- node = astroid.extract_node(
- """
- e.message #@
- """
- )
- with self.assertNoMessages():
- self.checker.visit_attribute(node)
-
- def test_invalid_codec(self):
- node = astroid.extract_node('foobar.encode("hex") #@')
- message = testutils.Message("invalid-str-codec", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_valid_codec(self):
- node = astroid.extract_node('foobar.encode("ascii", "ignore") #@')
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_visit_call_with_kwarg(self):
- node = astroid.extract_node('foobar.raz(encoding="hex") #@')
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_invalid_open_codec(self):
- node = astroid.extract_node('open(foobar, encoding="hex") #@')
- message = testutils.Message("invalid-str-codec", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_valid_open_codec(self):
- node = astroid.extract_node('open(foobar, encoding="palmos") #@')
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_using_cmp_argument(self):
- nodes = astroid.extract_node(
- """
- [].sort(cmp=lambda x: x) #@
- a = list(range(x))
- a.sort(cmp=lambda x: x) #@
-
- sorted([], cmp=lambda x: x) #@
- """
- )
- for node in nodes:
- message = testutils.Message("using-cmp-argument", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_sys_maxint(self):
- node = astroid.extract_node(
- """
- import sys
- sys.maxint #@
- """
- )
- message = testutils.Message("sys-max-int", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_attribute(node)
-
- def test_itertools_izip(self):
- node = astroid.extract_node(
- """
- from itertools import izip #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- message = testutils.Message("deprecated-itertools-function", node=node)
- with self.assertAddsMessages(absolute_import_message, message):
- self.checker.visit_importfrom(node)
-
- def test_deprecated_types_fields(self):
- node = astroid.extract_node(
- """
- from types import StringType #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- message = testutils.Message("deprecated-types-field", node=node)
- with self.assertAddsMessages(absolute_import_message, message):
- self.checker.visit_importfrom(node)
-
- def test_sys_maxint_imort_from(self):
- node = astroid.extract_node(
- """
- from sys import maxint #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- message = testutils.Message("sys-max-int", node=node)
- with self.assertAddsMessages(absolute_import_message, message):
- self.checker.visit_importfrom(node)
-
- def test_object_maxint(self):
- node = astroid.extract_node(
- """
- sys = object()
- sys.maxint #@
- """
- )
- with self.assertNoMessages():
- self.checker.visit_attribute(node)
-
- def test_bad_import(self):
- node = astroid.extract_node(
- """
- import urllib2, sys #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- message = testutils.Message("bad-python3-import", node=node)
- with self.assertAddsMessages(absolute_import_message, message):
- self.checker.visit_import(node)
-
- def test_bad_import_turtle(self):
- node = astroid.extract_node(
- """
- import turtle #@
- turtle.Turtle()
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- with self.assertAddsMessages(absolute_import_message):
- self.checker.visit_import(node)
-
- def test_bad_import_dbm(self):
- node = astroid.extract_node(
- """
- from dbm import open as open_ #@
- open_("dummy.db")
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- with self.assertAddsMessages(absolute_import_message):
- self.checker.visit_importfrom(node)
-
- def test_bad_import_conditional(self):
- node = astroid.extract_node(
- """
- import six
- if six.PY2:
- import urllib2 #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- with self.assertAddsMessages(absolute_import_message):
- self.checker.visit_import(node)
-
- def test_bad_import_try_except_handler(self):
- node = astroid.extract_node(
- """
- try:
- from hashlib import sha
- except:
- import sha #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- with self.assertAddsMessages(absolute_import_message):
- self.checker.visit_import(node)
-
- def test_bad_import_try(self):
- node = astroid.extract_node(
- """
- try:
- import md5 #@
- except:
- from hashlib import md5
- finally:
- pass
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- with self.assertAddsMessages(absolute_import_message):
- self.checker.visit_import(node)
-
- def test_bad_import_try_finally(self):
- node = astroid.extract_node(
- """
- try:
- import Queue #@
- finally:
- import queue
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- message = testutils.Message("bad-python3-import", node=node)
- with self.assertAddsMessages(absolute_import_message, message):
- self.checker.visit_import(node)
-
- def test_bad_import_from(self):
- node = astroid.extract_node(
- """
- from cStringIO import StringIO #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- message = testutils.Message("bad-python3-import", node=node)
- with self.assertAddsMessages(absolute_import_message, message):
- self.checker.visit_importfrom(node)
-
- def test_bad_string_attribute(self):
- node = astroid.extract_node(
- """
- import string
- string.maketrans #@
- """
- )
- message = testutils.Message("deprecated-string-function", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_attribute(node)
-
- def test_bad_operator_attribute(self):
- node = astroid.extract_node(
- """
- import operator
- operator.div #@
- """
- )
- message = testutils.Message("deprecated-operator-function", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_attribute(node)
-
- def test_comprehension_escape(self):
- assign, escaped_node = astroid.extract_node(
- """
- a = [i for i in range(10)] #@
- i #@
- """
- )
- good_module = astroid.parse(
- """
- {c for c in range(10)} #@
- {j:j for j in range(10)} #@
- [image_child] = [x for x in range(10)]
- thumbnail = func(__(image_child))
- """
- )
- message = testutils.Message("comprehension-escape", node=escaped_node)
- with self.assertAddsMessages(message):
- self.checker.visit_listcomp(assign.value)
-
- with self.assertNoMessages():
- self.walk(good_module)
-
- def test_comprehension_escape_newly_introduced(self):
- node = astroid.extract_node(
- """
- [i for i in range(3)]
- for i in range(3):
- i
- """
- )
- with self.assertNoMessages():
- self.walk(node)
-
- def test_exception_escape(self):
- module = astroid.parse(
- """
- try: 1/0
- except ValueError as exc:
- pass
- exc #@
- try:
- 2/0
- except (ValueError, TypeError) as exc:
- exc = 2
- exc #@
- try:
- 2/0
- except (ValueError, TypeError): #@
- exc = 2
- exc #@
- try:
- 1/0
- except (ValueError, TypeError) as exc:
- foo(bar for bar in exc.bar)
- """
- )
- message = testutils.Message("exception-escape", node=module.body[1].value)
- with self.assertAddsMessages(message):
- self.checker.visit_excepthandler(module.body[0].handlers[0])
- with self.assertNoMessages():
- self.checker.visit_excepthandler(module.body[2].handlers[0])
- self.checker.visit_excepthandler(module.body[4].handlers[0])
- self.checker.visit_excepthandler(module.body[6].handlers[0])
-
- def test_bad_sys_attribute(self):
- node = astroid.extract_node(
- """
- import sys
- sys.exc_clear #@
- """
- )
- message = testutils.Message("deprecated-sys-function", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_attribute(node)
-
- def test_bad_urllib_attribute(self):
- nodes = astroid.extract_node(
- """
- import urllib
- urllib.addbase #@
- urllib.splithost #@
- urllib.urlretrieve #@
- urllib.urlopen #@
- urllib.urlencode #@
- """
- )
- for node in nodes:
- message = testutils.Message("deprecated-urllib-function", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_attribute(node)
-
- def test_ok_string_attribute(self):
- node = astroid.extract_node(
- """
- import string
- string.ascii_letters #@
- """
- )
- with self.assertNoMessages():
- self.checker.visit_attribute(node)
-
- def test_bad_string_call(self):
- node = astroid.extract_node(
- """
- import string
- string.upper("hello world") #@
- """
- )
- message = testutils.Message("deprecated-string-function", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_ok_shadowed_call(self):
- node = astroid.extract_node(
- """
- import six.moves.configparser
- six.moves.configparser.ConfigParser() #@
- """
- )
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_ok_string_call(self):
- node = astroid.extract_node(
- """
- import string
- string.Foramtter() #@
- """
- )
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_bad_string_import_from(self):
- node = astroid.extract_node(
- """
- from string import atoi #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- message = testutils.Message("deprecated-string-function", node=node)
- with self.assertAddsMessages(absolute_import_message, message):
- self.checker.visit_importfrom(node)
-
- def test_ok_string_import_from(self):
- node = astroid.extract_node(
- """
- from string import digits #@
- """
- )
- absolute_import_message = testutils.Message("no-absolute-import", node=node)
- with self.assertAddsMessages(absolute_import_message):
- self.checker.visit_importfrom(node)
-
- def test_bad_str_translate_call_string_literal(self):
- node = astroid.extract_node(
- """
- foobar.translate(None, 'abc123') #@
- """
- )
- message = testutils.Message(
- "deprecated-str-translate-call", node=node, confidence=INFERENCE_FAILURE
- )
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_bad_str_translate_call_variable(self):
- node = astroid.extract_node(
- """
- def raz(foobar):
- foobar.translate(None, 'hello') #@
- """
- )
- message = testutils.Message(
- "deprecated-str-translate-call", node=node, confidence=INFERENCE_FAILURE
- )
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_bad_str_translate_call_infer_str(self):
- node = astroid.extract_node(
- """
- foobar = "hello world"
- foobar.translate(None, foobar) #@
- """
- )
- message = testutils.Message(
- "deprecated-str-translate-call", node=node, confidence=INFERENCE
- )
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_ok_str_translate_call_integer(self):
- node = astroid.extract_node(
- """
- foobar.translate(None, 33) #@
- """
- )
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_ok_str_translate_call_keyword(self):
- node = astroid.extract_node(
- """
- foobar.translate(None, 'foobar', raz=33) #@
- """
- )
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_ok_str_translate_call_not_str(self):
- node = astroid.extract_node(
- """
- foobar = {}
- foobar.translate(None, 'foobar') #@
- """
- )
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_non_py2_conditional(self):
- code = """
- from __future__ import absolute_import
- import sys
- x = {}
- if sys.maxsize:
- x.iterkeys() #@
- """
- node = astroid.extract_node(code)
- module = node.parent.parent
- message = testutils.Message("dict-iter-method", node=node)
- with self.assertAddsMessages(message):
- self.walk(module)
-
- def test_six_conditional(self):
- code = """
- from __future__ import absolute_import
- import six
- x = {}
- if six.PY2:
- x.iterkeys()
- """
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def test_versioninfo_conditional(self):
- code = """
- from __future__ import absolute_import
- import sys
- x = {}
- if sys.version_info[0] == 2:
- x.iterkeys()
- """
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def test_versioninfo_tuple_conditional(self):
- code = """
- from __future__ import absolute_import
- import sys
- x = {}
- if sys.version_info == (2, 7):
- x.iterkeys()
- """
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def test_six_ifexp_conditional(self):
- code = """
- from __future__ import absolute_import
- import six
- import string
- string.translate if six.PY2 else None
- """
- module = astroid.parse(code)
- with self.assertNoMessages():
- self.walk(module)
-
- def test_next_defined(self):
- node = astroid.extract_node(
- """
- class Foo(object):
- def next(self): #@
- pass"""
- )
- message = testutils.Message("next-method-defined", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_functiondef(node)
-
- def test_next_defined_too_many_args(self):
- node = astroid.extract_node(
- """
- class Foo(object):
- def next(self, foo=None): #@
- pass"""
- )
- with self.assertNoMessages():
- self.checker.visit_functiondef(node)
-
- def test_next_defined_static_method_too_many_args(self):
- node = astroid.extract_node(
- """
- class Foo(object):
- @staticmethod
- def next(self): #@
- pass"""
- )
- with self.assertNoMessages():
- self.checker.visit_functiondef(node)
-
- def test_next_defined_static_method(self):
- node = astroid.extract_node(
- """
- class Foo(object):
- @staticmethod
- def next(): #@
- pass"""
- )
- message = testutils.Message("next-method-defined", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_functiondef(node)
-
- def test_next_defined_class_method(self):
- node = astroid.extract_node(
- """
- class Foo(object):
- @classmethod
- def next(cls): #@
- pass"""
- )
- message = testutils.Message("next-method-defined", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_functiondef(node)
diff --git a/tests/functional/a/abstract/abstract_abc_methods.py b/tests/functional/a/abstract/abstract_abc_methods.py
index d174669a5..d63389c50 100644
--- a/tests/functional/a/abstract/abstract_abc_methods.py
+++ b/tests/functional/a/abstract/abstract_abc_methods.py
@@ -1,5 +1,5 @@
""" This should not warn about `prop` being abstract in Child """
-# pylint: disable=too-few-public-methods, no-absolute-import,metaclass-assignment, useless-object-inheritance
+# pylint: disable=too-few-public-methods, useless-object-inheritance
import abc
diff --git a/tests/functional/a/access/access_attr_before_def_false_positive.py b/tests/functional/a/access/access_attr_before_def_false_positive.py
index 00b7e40ed..fbad8c377 100644
--- a/tests/functional/a/access/access_attr_before_def_false_positive.py
+++ b/tests/functional/a/access/access_attr_before_def_false_positive.py
@@ -1,5 +1,5 @@
# pylint: disable=invalid-name,too-many-public-methods,attribute-defined-outside-init
-# pylint: disable=no-absolute-import, useless-object-inheritance,too-few-public-methods
+# pylint: disable= useless-object-inheritance,too-few-public-methods
"""This module demonstrates a possible problem of pyLint with calling __init__ s
from inherited classes.
Initializations done there are not considered, which results in Error E0203 for
diff --git a/tests/functional/a/access/access_to__name__.py b/tests/functional/a/access/access_to__name__.py
index 82dcdbe78..1a622824b 100644
--- a/tests/functional/a/access/access_to__name__.py
+++ b/tests/functional/a/access/access_to__name__.py
@@ -1,4 +1,4 @@
-# pylint: disable=too-few-public-methods, print-statement, useless-object-inheritance
+# pylint: disable=too-few-public-methods, useless-object-inheritance
"""test access to __name__ gives undefined member on new/old class instances
but not on new/old class object
"""
diff --git a/tests/functional/a/access/access_to_protected_members.py b/tests/functional/a/access/access_to_protected_members.py
index 06438400a..ffbfabf15 100644
--- a/tests/functional/a/access/access_to_protected_members.py
+++ b/tests/functional/a/access/access_to_protected_members.py
@@ -1,4 +1,4 @@
-# pylint: disable=too-few-public-methods, super-init-not-called, print-statement
+# pylint: disable=too-few-public-methods, super-init-not-called
# pylint: disable=no-classmethod-decorator,useless-object-inheritance
"""Test external access to protected class members."""
from __future__ import print_function
diff --git a/tests/functional/a/arguments.py b/tests/functional/a/arguments.py
index e1a8005aa..9e66ff18d 100644
--- a/tests/functional/a/arguments.py
+++ b/tests/functional/a/arguments.py
@@ -1,4 +1,4 @@
-# pylint: disable=too-few-public-methods, no-absolute-import,missing-docstring,import-error,wrong-import-position
+# pylint: disable=too-few-public-methods, missing-docstring,import-error,wrong-import-position
# pylint: disable=wrong-import-order, useless-object-inheritance,unnecessary-lambda, consider-using-f-string
def decorator(fun):
diff --git a/tests/functional/a/assign/assigning_non_slot.py b/tests/functional/a/assign/assigning_non_slot.py
index 4789014ff..cf673692f 100644
--- a/tests/functional/a/assign/assigning_non_slot.py
+++ b/tests/functional/a/assign/assigning_non_slot.py
@@ -1,7 +1,7 @@
""" Checks assigning attributes not found in class slots
will trigger assigning-non-slot warning.
"""
-# pylint: disable=too-few-public-methods, no-init, missing-docstring, no-absolute-import, import-error, useless-object-inheritance, redundant-u-string-prefix
+# pylint: disable=too-few-public-methods, no-init, missing-docstring, import-error, useless-object-inheritance, redundant-u-string-prefix
from collections import deque
from missing import Unknown
diff --git a/tests/functional/b/bad_reversed_sequence.py b/tests/functional/b/bad_reversed_sequence.py
index 0d7b84da0..101123330 100644
--- a/tests/functional/b/bad_reversed_sequence.py
+++ b/tests/functional/b/bad_reversed_sequence.py
@@ -1,6 +1,6 @@
""" Checks that reversed() receive proper argument """
# pylint: disable=missing-docstring, useless-object-inheritance
-# pylint: disable=too-few-public-methods,no-self-use,no-absolute-import
+# pylint: disable=too-few-public-methods,no-self-use
from collections import deque, OrderedDict
from enum import IntEnum
diff --git a/tests/functional/b/base_init_vars.py b/tests/functional/b/base_init_vars.py
index 08e2828ec..b77ec2b8d 100644
--- a/tests/functional/b/base_init_vars.py
+++ b/tests/functional/b/base_init_vars.py
@@ -1,7 +1,7 @@
-# pylint:disable=no-self-use, print-statement
+# pylint:disable=no-self-use
# pylint:disable=too-few-public-methods, useless-object-inheritance
"""Checks that class variables are seen as inherited !"""
-__revision__ = ''
+
class BaseClass(object):
"""A simple base class
diff --git a/tests/functional/c/cellvar_escaping_loop.py b/tests/functional/c/cellvar_escaping_loop.py
index d2c1fb4a5..5520fe949 100644
--- a/tests/functional/c/cellvar_escaping_loop.py
+++ b/tests/functional/c/cellvar_escaping_loop.py
@@ -1,4 +1,4 @@
-# pylint: disable=print-statement, unnecessary-comprehension,missing-docstring,too-few-public-methods
+# pylint: disable= unnecessary-comprehension,missing-docstring,too-few-public-methods
"""Tests for loopvar-in-closure."""
from __future__ import print_function
diff --git a/tests/functional/c/confidence_filter.rc b/tests/functional/c/confidence_filter.rc
index 74953b686..5d21cb56e 100644
--- a/tests/functional/c/confidence_filter.rc
+++ b/tests/functional/c/confidence_filter.rc
@@ -1,3 +1,3 @@
[Messages Control]
-disable=no-init,too-few-public-methods,undefined-variable,print-statement
+disable=no-init,too-few-public-methods,undefined-variable
confidence=INFERENCE,HIGH,UNDEFINED
diff --git a/tests/functional/d/defined_and_used_on_same_line.py b/tests/functional/d/defined_and_used_on_same_line.py
index d5bdb4db0..98e5077a6 100644
--- a/tests/functional/d/defined_and_used_on_same_line.py
+++ b/tests/functional/d/defined_and_used_on_same_line.py
@@ -1,5 +1,5 @@
"""Check for definitions and usage happening on the same line."""
-#pylint: disable=missing-docstring,multiple-statements,no-absolute-import,parameter-unpacking,wrong-import-position,unnecessary-comprehension,unspecified-encoding
+#pylint: disable=missing-docstring,multiple-statements,wrong-import-position,unnecessary-comprehension,unspecified-encoding
from __future__ import print_function
print([index
for index in range(10)])
diff --git a/tests/functional/d/dotted_ancestor.py b/tests/functional/d/dotted_ancestor.py
index 2c82d89a3..89826179a 100644
--- a/tests/functional/d/dotted_ancestor.py
+++ b/tests/functional/d/dotted_ancestor.py
@@ -1,9 +1,8 @@
"""bla"""
-# pylint: disable=no-absolute-import
+
from ..n.non import non_init_parent_called
-__revision__ = 'yo'
class Aaaa(non_init_parent_called.AAAA): # [too-few-public-methods]
"""test dotted name in ancestors"""
diff --git a/tests/functional/d/dotted_ancestor.txt b/tests/functional/d/dotted_ancestor.txt
index 4aa47e7c2..20f9dbee8 100644
--- a/tests/functional/d/dotted_ancestor.txt
+++ b/tests/functional/d/dotted_ancestor.txt
@@ -1 +1 @@
-too-few-public-methods:8:0:Aaaa:Too few public methods (0/2)
+too-few-public-methods:7:0:Aaaa:Too few public methods (0/2):HIGH
diff --git a/tests/functional/g/generated_members.rc b/tests/functional/g/generated_members.rc
index 8b61b4996..31b87ffd0 100644
--- a/tests/functional/g/generated_members.rc
+++ b/tests/functional/g/generated_members.rc
@@ -1,5 +1,5 @@
[Messages Control]
-disable=too-few-public-methods,print-statement
+disable=too-few-public-methods
[typecheck]
generated-members=
diff --git a/tests/functional/i/import_error.py b/tests/functional/i/import_error.py
index 09bf5560e..21c06d1e3 100644
--- a/tests/functional/i/import_error.py
+++ b/tests/functional/i/import_error.py
@@ -1,5 +1,5 @@
""" Test that import errors are detected. """
-# pylint: disable=invalid-name, unused-import, no-absolute-import, bare-except, broad-except, wrong-import-order, wrong-import-position
+# pylint: disable=invalid-name, unused-import, bare-except, broad-except, wrong-import-order, wrong-import-position
import totally_missing # [import-error]
try:
diff --git a/tests/functional/i/import_itself.py b/tests/functional/i/import_itself.py
index becd529d7..1f4928f3e 100644
--- a/tests/functional/i/import_itself.py
+++ b/tests/functional/i/import_itself.py
@@ -1,5 +1,5 @@
"""test module importing itself"""
-# pylint: disable=no-absolute-import,using-constant-test
+# pylint: disable=using-constant-test
from __future__ import print_function
from . import import_itself # [import-self]
diff --git a/tests/functional/i/inherit_non_class.py b/tests/functional/i/inherit_non_class.py
index ee9ef508c..bbee6bd9a 100644
--- a/tests/functional/i/inherit_non_class.py
+++ b/tests/functional/i/inherit_non_class.py
@@ -2,7 +2,7 @@
a class emits a warning. """
# pylint: disable=no-init, import-error, invalid-name, using-constant-test, useless-object-inheritance
-# pylint: disable=missing-docstring, too-few-public-methods, no-absolute-import
+# pylint: disable=missing-docstring, too-few-public-methods
from missing import Missing
diff --git a/tests/functional/i/invalid/e/invalid_exceptions_caught.py b/tests/functional/i/invalid/e/invalid_exceptions_caught.py
index 5cb6c84b8..c0298a06e 100644
--- a/tests/functional/i/invalid/e/invalid_exceptions_caught.py
+++ b/tests/functional/i/invalid/e/invalid_exceptions_caught.py
@@ -1,5 +1,5 @@
# pylint: disable=missing-docstring, too-few-public-methods, useless-object-inheritance, use-list-literal
-# pylint: disable=too-many-ancestors, no-absolute-import, import-error, multiple-imports,wrong-import-position
+# pylint: disable=too-many-ancestors, import-error, multiple-imports,wrong-import-position
from __future__ import print_function
import socket, binascii, abc, six
diff --git a/tests/functional/i/invalid/invalid_name.py b/tests/functional/i/invalid/invalid_name.py
index 07ad99b80..9ec81bfbf 100644
--- a/tests/functional/i/invalid/invalid_name.py
+++ b/tests/functional/i/invalid/invalid_name.py
@@ -1,5 +1,5 @@
""" Tests for invalid-name checker. """
-# pylint: disable=unused-import, no-absolute-import, wrong-import-position,import-outside-toplevel
+# pylint: disable=unused-import, wrong-import-position,import-outside-toplevel
AAA = 24
try:
diff --git a/tests/functional/l/len_checks.py b/tests/functional/l/len_checks.py
index 2cbefcbe7..ceeedb549 100644
--- a/tests/functional/l/len_checks.py
+++ b/tests/functional/l/len_checks.py
@@ -1,4 +1,4 @@
-# pylint: disable=too-few-public-methods,import-error, no-absolute-import,missing-docstring, misplaced-comparison-constant
+# pylint: disable=too-few-public-methods,import-error, missing-docstring, misplaced-comparison-constant
# pylint: disable=useless-super-delegation,wrong-import-position,invalid-name, wrong-import-order, condition-evals-to-constant
if len('TEST'): # [len-as-condition]
diff --git a/tests/functional/l/logging_format_interpolation.py b/tests/functional/l/logging_format_interpolation.py
index 782e3834b..5670ad57c 100644
--- a/tests/functional/l/logging_format_interpolation.py
+++ b/tests/functional/l/logging_format_interpolation.py
@@ -1,4 +1,4 @@
-# pylint: disable=no-member, no-absolute-import, import-error,line-too-long
+# pylint: disable=no-member, import-error,line-too-long
# pylint: disable=invalid-name,missing-docstring,wrong-import-order,wrong-import-position, consider-using-f-string
try:
import __builtin__ as builtins
diff --git a/tests/functional/m/member/member_checks.py b/tests/functional/m/member/member_checks.py
index ee79d1012..c1b6a22fb 100644
--- a/tests/functional/m/member/member_checks.py
+++ b/tests/functional/m/member/member_checks.py
@@ -1,4 +1,4 @@
-# pylint: disable=print-statement,missing-docstring,no-self-use,too-few-public-methods,bare-except,broad-except, useless-object-inheritance, unused-private-member
+# pylint: disable=missing-docstring,no-self-use,too-few-public-methods,bare-except,broad-except, useless-object-inheritance, unused-private-member
# pylint: disable=using-constant-test,expression-not-assigned, assigning-non-slot, unused-variable,pointless-statement, wrong-import-order, wrong-import-position,import-outside-toplevel
from __future__ import print_function
class Provider(object):
diff --git a/tests/functional/m/metaclass_attr_access.py b/tests/functional/m/metaclass_attr_access.py
index e6bf1cccb..50f9712fa 100644
--- a/tests/functional/m/metaclass_attr_access.py
+++ b/tests/functional/m/metaclass_attr_access.py
@@ -1,9 +1,9 @@
-# pylint: disable=too-few-public-methods, metaclass-assignment, useless-object-inheritance
+# pylint: disable=too-few-public-methods, useless-object-inheritance
"""test attribute access on metaclass"""
-
from __future__ import print_function
+
class Meta(type):
"""the meta class"""
def __init__(cls, name, bases, dictionary):
@@ -11,6 +11,7 @@ class Meta(type):
print(cls, cls._meta_args)
delattr(cls, '_meta_args')
+
class Test(object):
"""metaclassed class"""
__metaclass__ = Meta
diff --git a/tests/functional/m/method_hidden.py b/tests/functional/m/method_hidden.py
index 47031d8d0..cdbe323e2 100644
--- a/tests/functional/m/method_hidden.py
+++ b/tests/functional/m/method_hidden.py
@@ -1,4 +1,4 @@
-# pylint: disable=too-few-public-methods,print-statement, useless-object-inheritance,missing-docstring
+# pylint: disable=too-few-public-methods, useless-object-inheritance,missing-docstring
"""check method hidding ancestor attribute
"""
from __future__ import print_function
diff --git a/tests/functional/n/name/name_styles.py b/tests/functional/n/name/name_styles.py
index a9d74356c..27e6e1044 100644
--- a/tests/functional/n/name/name_styles.py
+++ b/tests/functional/n/name/name_styles.py
@@ -1,5 +1,5 @@
"""Test for the invalid-name warning."""
-# pylint: disable=no-absolute-import, useless-object-inheritance, unnecessary-pass, unnecessary-comprehension, unused-private-member
+# pylint: disable= useless-object-inheritance, unnecessary-pass, unnecessary-comprehension, unused-private-member
from __future__ import print_function
import abc
import collections
diff --git a/tests/functional/n/name/names_in__all__.py b/tests/functional/n/name/names_in__all__.py
index 9b2840acc..c5d17cd80 100644
--- a/tests/functional/n/name/names_in__all__.py
+++ b/tests/functional/n/name/names_in__all__.py
@@ -1,4 +1,4 @@
-# pylint: disable=too-few-public-methods,no-self-use, no-absolute-import,import-error, useless-object-inheritance, unnecessary-pass
+# pylint: disable=too-few-public-methods,no-self-use, import-error, useless-object-inheritance, unnecessary-pass
"""Test Pylint's use of __all__.
* NonExistant is not defined in this module, and it is listed in
diff --git a/tests/functional/n/new_style_class_py_30.py b/tests/functional/n/new_style_class_py_30.py
index 7a2a59a17..b70c6e097 100644
--- a/tests/functional/n/new_style_class_py_30.py
+++ b/tests/functional/n/new_style_class_py_30.py
@@ -6,7 +6,7 @@ from __future__ import print_function
__revision__ = None
-class File(file): # pylint: disable=file-builtin,undefined-variable
+class File(file): # pylint: disable=undefined-variable
""" Testing new-style class inheritance from file"""
def __init__(self, name, mode="r", buffering=-1, verbose=False):
"""Constructor"""
diff --git a/tests/functional/n/no/no_name_in_module.py b/tests/functional/n/no/no_name_in_module.py
index e3ea9469b..ba67fbdb7 100644
--- a/tests/functional/n/no/no_name_in_module.py
+++ b/tests/functional/n/no/no_name_in_module.py
@@ -1,4 +1,4 @@
-# pylint: disable=wildcard-import,unused-import,no-absolute-import,invalid-name,import-error,
+# pylint: disable=wildcard-import,unused-import,invalid-name,import-error
# pylint: disable=bare-except,broad-except,wrong-import-order,ungrouped-imports,wrong-import-position
"""check nonexistent names imported are reported"""
from __future__ import print_function
diff --git a/tests/functional/n/non/non_init_parent_called.py b/tests/functional/n/non/non_init_parent_called.py
index 1ecc8f16a..97489accf 100644
--- a/tests/functional/n/non/non_init_parent_called.py
+++ b/tests/functional/n/non/non_init_parent_called.py
@@ -1,5 +1,5 @@
# pylint: disable=protected-access,import-self,too-few-public-methods,line-too-long
-# pylint: disable=no-absolute-import,wrong-import-order, useless-object-inheritance,
+# pylint: disable=wrong-import-order, useless-object-inheritance,
"""test for call to __init__ from a non ancestor class
"""
from __future__ import print_function
diff --git a/tests/functional/n/nonlocal_without_binding.py b/tests/functional/n/nonlocal_without_binding.py
index be3c00371..22887bcee 100644
--- a/tests/functional/n/nonlocal_without_binding.py
+++ b/tests/functional/n/nonlocal_without_binding.py
@@ -1,6 +1,6 @@
""" Checks that reversed() receive proper argument """
# pylint: disable=missing-docstring,invalid-name,unused-variable, useless-object-inheritance
-# pylint: disable=too-few-public-methods,no-self-use,no-absolute-import
+# pylint: disable=too-few-public-methods,no-self-use
def test():
def parent():
diff --git a/tests/functional/s/slots_checks.py b/tests/functional/s/slots_checks.py
index c8cfd04e0..79912b65c 100644
--- a/tests/functional/s/slots_checks.py
+++ b/tests/functional/s/slots_checks.py
@@ -1,6 +1,6 @@
""" Checks that classes uses valid __slots__ """
-# pylint: disable=too-few-public-methods, missing-docstring, no-absolute-import, useless-object-inheritance
+# pylint: disable=too-few-public-methods, missing-docstring, useless-object-inheritance
# pylint: disable=using-constant-test, wrong-import-position, no-else-return, line-too-long, unused-private-member
from collections import deque
diff --git a/tests/functional/s/string/string_formatting.py b/tests/functional/s/string/string_formatting.py
index 6d2b18665..8372a4373 100644
--- a/tests/functional/s/string/string_formatting.py
+++ b/tests/functional/s/string/string_formatting.py
@@ -1,6 +1,6 @@
"""Test for Python 3 string formatting error"""
-# pylint: disable=too-few-public-methods, import-error, unused-argument, line-too-long, no-absolute-import,
+# pylint: disable=too-few-public-methods, import-error, unused-argument, line-too-long,
# pylint: disable=useless-object-inheritance, consider-using-f-string
import os
import sys
diff --git a/tests/functional/s/string/string_formatting_error.py b/tests/functional/s/string/string_formatting_error.py
index d48b47d3f..681fedd56 100644
--- a/tests/functional/s/string/string_formatting_error.py
+++ b/tests/functional/s/string/string_formatting_error.py
@@ -1,5 +1,5 @@
"""test string format error"""
-# pylint: disable=print-statement,unsupported-binary-operation,line-too-long, consider-using-f-string
+# pylint: disable=unsupported-binary-operation,line-too-long, consider-using-f-string
from __future__ import print_function
PARG_1 = PARG_2 = PARG_3 = 1
diff --git a/tests/functional/s/string/string_log_formatting.py b/tests/functional/s/string/string_log_formatting.py
index e03d47f59..3bed980f7 100644
--- a/tests/functional/s/string/string_log_formatting.py
+++ b/tests/functional/s/string/string_log_formatting.py
@@ -1,15 +1,15 @@
-# pylint: disable=no-absolute-import
-"""Test checking of log format strings
+"""
+Test checking of log format strings
"""
import logging
-__revision__ = ''
-
def pprint():
- """Test string format in logging statements.
"""
+ Test string format in logging statements.
+ """
+
# These should all emit lint errors:
logging.info(0, '') # [logging-too-many-args]
logging.info('', '') # [logging-too-many-args]
diff --git a/tests/functional/s/super/super_checks.py b/tests/functional/s/super/super_checks.py
index 3f132dff1..277feae7e 100644
--- a/tests/functional/s/super/super_checks.py
+++ b/tests/functional/s/super/super_checks.py
@@ -1,4 +1,4 @@
-# pylint: disable=too-few-public-methods,import-error, no-absolute-import,missing-docstring, useless-object-inheritance
+# pylint: disable=too-few-public-methods,import-error, missing-docstring, useless-object-inheritance
# pylint: disable=useless-super-delegation,wrong-import-position,invalid-name, wrong-import-order
# pylint: disable=super-with-arguments
from unknown import Missing
diff --git a/tests/functional/u/unpacking_non_sequence.py b/tests/functional/u/unpacking_non_sequence.py
index c681641ca..b7ea2189c 100644
--- a/tests/functional/u/unpacking_non_sequence.py
+++ b/tests/functional/u/unpacking_non_sequence.py
@@ -1,6 +1,6 @@
"""Check unpacking non-sequences in assignments. """
-# pylint: disable=too-few-public-methods, invalid-name, attribute-defined-outside-init, unused-variable, no-absolute-import
+# pylint: disable=too-few-public-methods, invalid-name, attribute-defined-outside-init, unused-variable
# pylint: disable=using-constant-test, no-init, missing-docstring, wrong-import-order,wrong-import-position,no-else-return, useless-object-inheritance
from os import rename as nonseq_func
from functional.u.unpacking import nonseq
diff --git a/tests/functional/u/unused/unused_argument.py b/tests/functional/u/unused/unused_argument.py
index c5f534259..a3fd4e6ab 100644
--- a/tests/functional/u/unused/unused_argument.py
+++ b/tests/functional/u/unused/unused_argument.py
@@ -47,7 +47,7 @@ def metadata_from_dict(key):
"""
return {key: str(value) for key, value in key.items()}
-# pylint: disable=too-few-public-methods, print-statement, misplaced-future,wrong-import-position
+# pylint: disable=too-few-public-methods, misplaced-future,wrong-import-position
from __future__ import print_function
diff --git a/tests/functional/u/unused/unused_import.py b/tests/functional/u/unused/unused_import.py
index c6c2f20be..3bf17c6c9 100644
--- a/tests/functional/u/unused/unused_import.py
+++ b/tests/functional/u/unused/unused_import.py
@@ -1,5 +1,5 @@
"""unused import"""
-# pylint: disable=undefined-all-variable, import-error, no-absolute-import, too-few-public-methods, missing-docstring,wrong-import-position, useless-object-inheritance, multiple-imports
+# pylint: disable=undefined-all-variable, import-error, too-few-public-methods, missing-docstring,wrong-import-position, useless-object-inheritance, multiple-imports
import xml.etree # [unused-import]
import xml.sax # [unused-import]
import os.path as test # [unused-import]
diff --git a/tests/functional/u/unused/unused_name_from_wilcard_import.py b/tests/functional/u/unused/unused_name_from_wilcard_import.py
index 56f5b600e..292d40f95 100644
--- a/tests/functional/u/unused/unused_name_from_wilcard_import.py
+++ b/tests/functional/u/unused/unused_name_from_wilcard_import.py
@@ -1,3 +1,3 @@
"""check unused import from a wildcard import"""
-# pylint: disable=no-absolute-import,line-too-long
+# pylint: disable=line-too-long
from .unused_argument_py3 import * # [unused-wildcard-import, unused-wildcard-import, wildcard-import]
diff --git a/tests/functional/w/wildcard_import.py b/tests/functional/w/wildcard_import.py
index 66ae63d9e..4034162e0 100644
--- a/tests/functional/w/wildcard_import.py
+++ b/tests/functional/w/wildcard_import.py
@@ -1,4 +1,4 @@
-# pylint: disable=no-absolute-import,missing-docstring,import-error,unused-wildcard-import
+# pylint: disable=missing-docstring,import-error,unused-wildcard-import
from indirect1 import * # [wildcard-import]
# This is an unresolved import which still generates the wildcard-import
# warning.
diff --git a/tests/input/func_3k_removed_stuff_py_30.py b/tests/input/func_3k_removed_stuff_py_30.py
index 54ad935bc..d844c5603 100644
--- a/tests/input/func_3k_removed_stuff_py_30.py
+++ b/tests/input/func_3k_removed_stuff_py_30.py
@@ -1,5 +1,5 @@
"""test relative import"""
-# pylint: disable=no-absolute-import
+
from __future__ import print_function
import func_w0401
__revision__ = filter(None, map(str, (1, 2, 3)))
diff --git a/tests/input/func_w0332_py_30.py b/tests/input/func_w0332_py_30.py
deleted file mode 100644
index 6a38e8c0d..000000000
--- a/tests/input/func_w0332_py_30.py
+++ /dev/null
@@ -1,4 +0,0 @@
-"""check use of l as long int marker
-"""
-# pylint: disable=long-suffix
-__revision__ = 1l
diff --git a/tests/input/func_w0401.py b/tests/input/func_w0401.py
index 12227bc9a..f8fae2447 100644
--- a/tests/input/func_w0401.py
+++ b/tests/input/func_w0401.py
@@ -1,6 +1,6 @@
"""test cyclic import
"""
-# pylint: disable=no-absolute-import
+
from __future__ import print_function
from . import w0401_cycle
diff --git a/tests/input/func_w0401_disabled.py b/tests/input/func_w0401_disabled.py
index 966706caf..955188f08 100644
--- a/tests/input/func_w0401_disabled.py
+++ b/tests/input/func_w0401_disabled.py
@@ -1,6 +1,6 @@
"""test cyclic import
"""
-# pylint: disable=no-absolute-import
+
from __future__ import print_function
from . import w0401_cycle # pylint: disable=cyclic-import
diff --git a/tests/input/func_w0401_disabled_in_func.py b/tests/input/func_w0401_disabled_in_func.py
index 69f266863..c0013d831 100644
--- a/tests/input/func_w0401_disabled_in_func.py
+++ b/tests/input/func_w0401_disabled_in_func.py
@@ -1,6 +1,6 @@
"""Test disabling of cyclic import check inside a function
"""
-# pylint: disable=no-absolute-import,import-outside-toplevel
+# pylint: disable=import-outside-toplevel
from __future__ import print_function
diff --git a/tests/input/func_w0401_package/all_the_things.py b/tests/input/func_w0401_package/all_the_things.py
index b8bd47b9e..64556e1be 100644
--- a/tests/input/func_w0401_package/all_the_things.py
+++ b/tests/input/func_w0401_package/all_the_things.py
@@ -1,5 +1,5 @@
"""All the things!"""
-# pylint: disable=no-absolute-import
+
from .thing1 import THING1
from .thing2 import THING2
from .thing2 import THING1_PLUS_THING2
diff --git a/tests/input/func_w0401_package/thing2.py b/tests/input/func_w0401_package/thing2.py
index 80bec1dd8..d7a0f2239 100644
--- a/tests/input/func_w0401_package/thing2.py
+++ b/tests/input/func_w0401_package/thing2.py
@@ -1,5 +1,5 @@
"""The second thing."""
-# pylint: disable=no-absolute-import
+
from .all_the_things import THING1
__revision__ = None
diff --git a/tests/input/no_absolute_import.py b/tests/input/no_absolute_import.py
deleted file mode 100644
index 69059417f..000000000
--- a/tests/input/no_absolute_import.py
+++ /dev/null
@@ -1,5 +0,0 @@
-""" Puts issue #2672 under test (-j 1 vs -j N)
-
-Here we use a simple file to ensure configs are treated exactly the same way in -j 1 and
--j N """
-import os # pylint: disable=unused-import
diff --git a/tests/input/w0401_cycle.py b/tests/input/w0401_cycle.py
index ddb42557e..37be7c562 100644
--- a/tests/input/w0401_cycle.py
+++ b/tests/input/w0401_cycle.py
@@ -1,6 +1,6 @@
"""w0401 dependency
"""
-# pylint: disable=print-statement, no-absolute-import
+
from __future__ import print_function
from . import func_w0401
diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py
index fee47c9cf..110a2061c 100644
--- a/tests/lint/unittest_lint.py
+++ b/tests/lint/unittest_lint.py
@@ -575,15 +575,6 @@ def test_analyze_explicit_script(linter):
assert ["C: 2: Line too long (175/100)"] == linter.reporter.messages
-def test_python3_checker_disabled(linter):
- checker_names = [c.name for c in linter.prepare_checkers()]
- assert "python3" not in checker_names
-
- linter.set_option("enable", "python3")
- checker_names = [c.name for c in linter.prepare_checkers()]
- assert "python3" in checker_names
-
-
def test_full_documentation(linter):
out = StringIO()
linter.print_full_documentation(out)
@@ -592,9 +583,9 @@ def test_full_documentation(linter):
for re_str in (
# autogenerated text
"^Pylint global options and switches$",
- "Verbatim name of the checker is ``python3``",
+ "Verbatim name of the checker is ``variables``",
# messages
- "^:old-octal-literal \\(E1608\\):",
+ "^:undefined-loop-variable \\(W0631\\): *",
# options
"^:dummy-variables-rgx:",
):
diff --git a/tests/regrtest_data/func_block_disable_msg.py b/tests/regrtest_data/func_block_disable_msg.py
index 36198db2b..8a94ab4f3 100644
--- a/tests/regrtest_data/func_block_disable_msg.py
+++ b/tests/regrtest_data/func_block_disable_msg.py
@@ -1,4 +1,4 @@
-# pylint: disable=C0302,bare-except,print-statement, useless-object-inheritance
+# pylint: disable=C0302,bare-except, useless-object-inheritance
"""pylint option block-disable"""
from __future__ import print_function
diff --git a/tests/regrtest_data/py3k-disabled.rc b/tests/regrtest_data/py3k-disabled.rc
deleted file mode 100644
index 41d775778..000000000
--- a/tests/regrtest_data/py3k-disabled.rc
+++ /dev/null
@@ -1,2 +0,0 @@
-[MESSAGES CONTROL]
-disable=no-absolute-import
diff --git a/tests/regrtest_data/py3k_error_flag.py b/tests/regrtest_data/py3k_error_flag.py
deleted file mode 100644
index 6bead4102..000000000
--- a/tests/regrtest_data/py3k_error_flag.py
+++ /dev/null
@@ -1,11 +0,0 @@
-"""Contains both normal error messages and Python3 porting error messages."""
-# pylint: disable=too-few-public-methods
-
-raise Exception, 1 # Error emitted here with the Python 3 checker.
-
-
-class Test(object):
- """dummy"""
-
- def __init__(self):
- return 42
diff --git a/tests/regrtest_data/py3k_errors_and_warnings.py b/tests/regrtest_data/py3k_errors_and_warnings.py
deleted file mode 100644
index 3d033e86c..000000000
--- a/tests/regrtest_data/py3k_errors_and_warnings.py
+++ /dev/null
@@ -1,19 +0,0 @@
-"""Contains both normal error messages and Python3 porting error messages."""
-# pylint: disable=too-few-public-methods
-
-# error: import missing `from __future__ import absolute_import`
-import sys
-
-# error: Use raise ErrorClass(args) instead of raise ErrorClass, args.
-raise Exception, 1
-
-class Test(object):
- """dummy"""
-
- def __init__(self):
- # warning: Calling a dict.iter*() method
- {1: 2}.iteritems()
- return 42
-
-# error: print statement used
-print 'not in python3'
diff --git a/tests/test_self.py b/tests/test_self.py
index 519899021..2bf635176 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -290,32 +290,9 @@ class TestRunTC:
in out.getvalue().strip()
)
- def test_parallel_execution_bug_2674(self):
- """Tests that disabling absolute imports works the same in -j1/j2"""
- expected_ret_code = 0 # we are disabling the check, should pass
- for jobs in (1, 2):
- self._runtest(
- [
- "--py3k",
- "--disable=no-absolute-import",
- f"-j {int(jobs)}",
- join(HERE, "input", "no_absolute_import.py"),
- ],
- code=expected_ret_code,
- )
-
def test_parallel_execution_missing_arguments(self):
self._runtest(["-j 2", "not_here", "not_here_too"], code=1)
- def test_py3k_option(self):
- # Test that --py3k flag works.
- rc_code = 0
- self._runtest([UNNECESSARY_LAMBDA, "--py3k"], code=rc_code)
-
- def test_py3k_jobs_option(self):
- rc_code = 0
- self._runtest([UNNECESSARY_LAMBDA, "--py3k", "-j 2"], code=rc_code)
-
def test_abbreviations_are_not_supported(self):
expected = "no such option: --load-plugin"
self._test_output([".", "--load-plugin"], expected_output=expected)