88 def deprecated_function():
99 pass
1010
11+ def myfunction(arg0, arg1, deprecated_arg1=None, arg2='foo', arg3='bar', deprecated_arg2='spam'):
12+ pass
13+
1114 class MyClass:
1215 def deprecated_method(self):
1316 pass
1417
18+ def mymethod(self, arg0, arg1, deprecated1=None, arg2='foo', deprecated2='bar', arg3='spam'):
19+ pass
20+
1521 $ cat mymain.py
16- from mymodule import deprecated_function, MyClass
22+ from mymodule import deprecated_function, myfunction, MyClass
1723
1824 deprecated_function()
25+ myfunction(0, 1, 'deprecated_arg1', deprecated_arg2=None)
1926 MyClass().deprecated_method()
27+ MyClass().mymethod(0, 1, deprecated1=None, deprecated2=None)
2028
2129 $ pylint --load-plugins=deprecation_checker mymain.py
2230 ************* Module mymain
2331 mymain.py:3:0: W1505: Using deprecated method deprecated_function() (deprecated-method)
24- mymain.py:4:0: W1505: Using deprecated method deprecated_method() (deprecated-method)
32+ mymain.py:4:0: W1511: Using deprecated argument deprecated_arg1 of method myfunction() (deprecated-argument)
33+ mymain.py:4:0: W1511: Using deprecated argument deprecated_arg2 of method myfunction() (deprecated-argument)
34+ mymain.py:5:0: W1505: Using deprecated method deprecated_method() (deprecated-method)
35+ mymain.py:6:0: W1511: Using deprecated argument deprecated1 of method mymethod() (deprecated-argument)
36+ mymain.py:6:0: W1511: Using deprecated argument deprecated2 of method mymethod() (deprecated-argument)
2537
2638 ------------------------------------------------------------------
27- Your code has been rated at 3.33 /10 (previous run: 3.33 /10, +0.00)
39+ Your code has been rated at 2.00 /10 (previous run: 2.00 /10, +0.00)
2840"""
2941
30- import astroid
3142
32- from pylint .checkers import BaseChecker , DeprecatedMixin , utils
43+ from pylint .checkers import BaseChecker , DeprecatedMixin
3344from pylint .interfaces import IAstroidChecker
3445
3546
@@ -45,24 +56,6 @@ class DeprecationChecker(DeprecatedMixin, BaseChecker):
4556 # The name defines a custom section of the config for this checker.
4657 name = "deprecated"
4758
48- @utils .check_messages (
49- "deprecated-method" ,
50- )
51- def visit_call (self , node ):
52- """Called when a :class:`.astroid.node_classes.Call` node is visited.
53-
54- See :mod:`astroid` for the description of available nodes.
55-
56- :param node: The node to check.
57- :type node: astroid.node_classes.Call
58- """
59- try :
60- for inferred in node .func .infer ():
61- # Calling entry point for deprecation check logic.
62- self .check_deprecated_method (node , inferred )
63- except astroid .InferenceError :
64- return
65-
6659 def deprecated_methods (self ):
6760 """Callback method called by DeprecatedMixin for every method/function found in the code.
6861
@@ -71,6 +64,29 @@ def deprecated_methods(self):
7164 """
7265 return {"mymodule.deprecated_function" , "mymodule.MyClass.deprecated_method" }
7366
67+ def deprecated_arguments (self , method : str ):
68+ """Callback returning the deprecated arguments of method/function.
69+
70+ Returns:
71+ collections.abc.Iterable in form:
72+ ((POSITION1, PARAM1), (POSITION2: PARAM2) ...)
73+ where
74+ * POSITIONX - position of deprecated argument PARAMX in function definition.
75+ If argument is keyword-only, POSITIONX should be None.
76+ * PARAMX - name of the deprecated argument.
77+ """
78+ if method == "mymodule.myfunction" :
79+ # myfunction() has two deprecated arguments:
80+ # * deprecated_arg1 defined at 2nd position and
81+ # * deprecated_arg2 defined at 5th position.
82+ return ((2 , "deprecated_arg1" ), (5 , "deprecated_arg2" ))
83+ if method == "mymodule.MyClass.mymethod" :
84+ # mymethod() has two deprecated arguments:
85+ # * deprecated1 defined at 2nd position and
86+ # * deprecated2 defined at 4th position.
87+ return ((2 , "deprecated1" ), (4 , "deprecated2" ))
88+ return ()
89+
7490
7591def register (linter ):
7692 """This required method auto registers the checker.
0 commit comments