summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-10-02 09:32:29 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-10-02 09:32:29 +0200
commitf9c2ffe84d235b82583c04677b7ceb370445c303 (patch)
treee9b5c0c6e851cf6dd1863e04ba532e8d3478fe40
parent50568bab26ba5d67a8d4f23c3bc11dbb24190c9d (diff)
downloadpylint-git-f9c2ffe84d235b82583c04677b7ceb370445c303.tar.gz
``deprecated-method`` can use the attribute name for identifying a deprecated method
Previously we were using the fully qualified name, which we still do, but the fully qualified name for some ``unittest`` deprecated aliases leads to a generic deprecation function. Instead on relying on that, we now also rely on the attribute name, which should solve some false positives. Close #1653 Close #1946
-rw-r--r--ChangeLog10
-rw-r--r--pylint/checkers/stdlib.py62
-rw-r--r--pylint/test/functional/deprecated_methods_py3.py3
3 files changed, 52 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index eb2ea6134..62a75d27d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,16 @@ What's New in Pylint 2.2?
Release date: TBA
+ * ``deprecated-method`` can use the attribute name for identifying a deprecated method
+
+ Previously we were using the fully qualified name, which we still do, but the fully
+ qualified name for some ``unittest`` deprecated aliases leads to a generic
+ deprecation function. Instead on relying on that, we now also rely on the attribute
+ name, which should solve some false positives.
+
+ Close #1653
+ Close #1946
+
* Fix compatibility with changes to stdlib tokenizer.
* ``pylint`` is less eager to consume the whole line for pragmas
diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py
index 872d91330..57692b93d 100644
--- a/pylint/checkers/stdlib.py
+++ b/pylint/checkers/stdlib.py
@@ -151,7 +151,7 @@ class StdlibChecker(BaseChecker):
}
deprecated = {
- 0: [
+ 0: {
"cgi.parse_qs",
"cgi.parse_qsl",
"ctypes.c_buffer",
@@ -159,16 +159,16 @@ class StdlibChecker(BaseChecker):
"distutils.command.sdist.sdist.check_metadata",
"tkinter.Misc.tk_menuBar",
"tkinter.Menu.tk_bindForTraversal",
- ],
+ },
2: {
- (2, 6, 0): [
+ (2, 6, 0): {
"commands.getstatus",
"os.popen2",
"os.popen3",
"os.popen4",
"macostools.touched",
- ],
- (2, 7, 0): [
+ },
+ (2, 7, 0): {
"unittest.case.TestCase.assertEquals",
"unittest.case.TestCase.assertNotEquals",
"unittest.case.TestCase.assertAlmostEquals",
@@ -178,43 +178,57 @@ class StdlibChecker(BaseChecker):
"xml.etree.ElementTree.Element.getiterator",
"xml.etree.ElementTree.XMLParser.getiterator",
"xml.etree.ElementTree.XMLParser.doctype",
- ],
+ },
},
3: {
- (3, 0, 0): [
+ (3, 0, 0): {
"inspect.getargspec",
- "unittest.case.TestCase._deprecate.deprecated_func",
- ],
- (3, 1, 0): [
+ "failUnlessEqual",
+ "assertEquals",
+ "failIfEqual",
+ "assertNotEquals",
+ "failUnlessAlmostEqual",
+ "assertAlmostEquals",
+ "failIfAlmostEqual",
+ "assertNotAlmostEquals",
+ "failUnless",
+ "assert_",
+ "failUnlessRaises",
+ "failIf",
+ "assertRaisesRegexp",
+ "assertRegexpMatches",
+ "assertNotRegexpMatches",
+ },
+ (3, 1, 0): {
"base64.encodestring",
"base64.decodestring",
"ntpath.splitunc",
- ],
- (3, 2, 0): [
+ },
+ (3, 2, 0): {
"cgi.escape",
"configparser.RawConfigParser.readfp",
"xml.etree.ElementTree.Element.getchildren",
"xml.etree.ElementTree.Element.getiterator",
"xml.etree.ElementTree.XMLParser.getiterator",
"xml.etree.ElementTree.XMLParser.doctype",
- ],
- (3, 3, 0): [
+ },
+ (3, 3, 0): {
"inspect.getmoduleinfo",
"logging.warn",
"logging.Logger.warn",
"logging.LoggerAdapter.warn",
"nntplib._NNTPBase.xpath",
"platform.popen",
- ],
- (3, 4, 0): [
+ },
+ (3, 4, 0): {
"importlib.find_loader",
"plistlib.readPlist",
"plistlib.writePlist",
"plistlib.readPlistFromBytes",
"plistlib.writePlistToBytes",
- ],
- (3, 4, 4): ["asyncio.tasks.async"],
- (3, 5, 0): [
+ },
+ (3, 4, 4): {"asyncio.tasks.async"},
+ (3, 5, 0): {
"fractions.gcd",
"inspect.getargvalues",
"inspect.formatargspec",
@@ -222,8 +236,8 @@ class StdlibChecker(BaseChecker):
"inspect.getcallargs",
"platform.linux_distribution",
"platform.dist",
- ],
- (3, 6, 0): ["importlib._bootstrap_external.FileLoader.load_module"],
+ },
+ (3, 6, 0): {"importlib._bootstrap_external.FileLoader.load_module"},
},
}
@@ -319,11 +333,13 @@ class StdlibChecker(BaseChecker):
return
qname = inferred.qname()
- if qname in self.deprecated[0]:
+ if any(name in self.deprecated[0] for name in (qname, func_name)):
self.add_message("deprecated-method", node=node, args=(func_name,))
else:
for since_vers, func_list in self.deprecated[py_vers].items():
- if since_vers <= sys.version_info and qname in func_list:
+ if since_vers <= sys.version_info and any(
+ name in func_list for name in (qname, func_name)
+ ):
self.add_message("deprecated-method", node=node, args=(func_name,))
break
diff --git a/pylint/test/functional/deprecated_methods_py3.py b/pylint/test/functional/deprecated_methods_py3.py
index 6ee7a831c..d390c8d79 100644
--- a/pylint/test/functional/deprecated_methods_py3.py
+++ b/pylint/test/functional/deprecated_methods_py3.py
@@ -45,3 +45,6 @@ class Tests(unittest.TestCase):
self.assertAlmostEquals(2 + 2, 4) # [deprecated-method]
self.assertNotAlmostEquals(2 + 2, 4) # [deprecated-method]
self.assert_("abc" == "2") # [deprecated-method]
+
+ self.assertRaisesRegex(ValueError, "exception")
+ self.assertRegex("something", r".+")