Skip to content

Commit

Permalink
deprecated-method can use the attribute name for identifying a de…
Browse files Browse the repository at this point in the history
…precated 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
  • Loading branch information
PCManticore committed Oct 2, 2018
1 parent 50568ba commit f9c2ffe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 39 additions & 23 deletions pylint/checkers/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,24 @@ class StdlibChecker(BaseChecker):
}

deprecated = {
0: [
0: {
"cgi.parse_qs",
"cgi.parse_qsl",
"ctypes.c_buffer",
"distutils.command.register.register.check_metadata",
"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",
Expand All @@ -178,52 +178,66 @@ 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",
"inspect.formatargvalues",
"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"},
},
}

Expand Down Expand Up @@ -319,11 +333,13 @@ def _check_deprecated_method(self, node, inferred):
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

Expand Down
3 changes: 3 additions & 0 deletions pylint/test/functional/deprecated_methods_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ def test_foo(self):
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".+")

0 comments on commit f9c2ffe

Please sign in to comment.