You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately, there is no easy way how it can be simply reused to add support for deprecation checks in pylint plugins.
Describe the solution you'd like
Extend solution proposed in #4049 and #4051 to support also deprecated modules
Additional context
The final plugin can look like as follows:
importastroidfrompylint.checkersimportBaseChecker, DeprecatedMixin, utilsfrompylint.interfacesimportIAstroidCheckerclassDeprecationChecker(BaseChecker, DeprecatedMixin):
__implements__= (IAstroidChecker,)
name="deprecated"msgs= {
"W0002": (
"Using deprecated method %s()",
"deprecated-method",
"The method is marked as deprecated and will be removed in ""the future.",
),
"W0003": (
"Using deprecated module %s()",
"deprecated-module",
"The module is marked as deprecated and will be removed in ""the future.",
),
}
defvisit_call(self, node):
try:
forinferredinnode.func.infer():
# Calling entry point for deprecation check logic.self.check_deprecated_method(node, inferred)
exceptastroid.InferenceError:
returndefvisit_import(self, node):
"""triggered when an import statement is seen"""names= [nameforname, _innode.names]
fornameinnames:
self._check_deprecated_module(node, name)
defvisit_importfrom(self, node):
"""triggered when a from statement is seen"""basename=node.modnameself.check_deprecated_module(node, basename)
defdeprecated_methods(self):
return {'mymodule.deprecated_function', 'mymodule.MyClass.deprecated_method'}
defdeprecated_modules(self):
return {'deprecated_module1', 'deprecated_module2'}
defregister(linter):
linter.register_checker(DeprecationChecker(linter))
The text was updated successfully, but these errors were encountered:
Another possible improvement can be that Mixin class will also contain predefined implementation of visit_* methods (which can be of course overwritten) with default logic. Hence, the straightforward usage of the mixin will be even more simple just defining following class:
importastroidfrompylint.checkersimportBaseChecker, DeprecatedMixin, utilsfrompylint.interfacesimportIAstroidCheckerclassDeprecationChecker(BaseChecker, DeprecatedMixin):
__implements__= (IAstroidChecker,)
name="deprecated"msgs= {
"W0002": (
"Using deprecated method %s()",
"deprecated-method",
"The method is marked as deprecated and will be removed in ""the future.",
),
"W0003": (
"Using deprecated module %s()",
"deprecated-module",
"The module is marked as deprecated and will be removed in ""the future.",
),
}
defdeprecated_methods(self):
return {'mymodule.deprecated_function', 'mymodule.MyClass.deprecated_method'}
defdeprecated_modules(self):
return {'deprecated_module1', 'deprecated_module2'}
defregister(linter):
linter.register_checker(DeprecationChecker(linter))
Is your feature request related to a problem? Please describe
Imports checker contains checks for deprecated modules:
pylint/pylint/checkers/imports.py
https://github.com/PyCQA/pylint/blob/d825c21e18de5618cfcacea0fd818efa80a6b0fe/pylint/checkers/imports.py#L229-L233
Unfortunately, there is no easy way how it can be simply reused to add support for deprecation checks in pylint plugins.
Describe the solution you'd like
Extend solution proposed in #4049 and #4051 to support also deprecated modules
Additional context
The final plugin can look like as follows:
The text was updated successfully, but these errors were encountered: