diff --git a/scripts/pylint_custom_plugin/pylint_guidelines_checker.py b/scripts/pylint_custom_plugin/pylint_guidelines_checker.py index f44725df8411..3fbd1b3bca67 100644 --- a/scripts/pylint_custom_plugin/pylint_guidelines_checker.py +++ b/scripts/pylint_custom_plugin/pylint_guidelines_checker.py @@ -1916,7 +1916,53 @@ def visit_module(self, node): logger.debug("Pylint custom checker failed to check if model is aliased.") pass +class TypingOverloadReturnNone(BaseChecker): + __implements__ = IAstroidChecker + + name = "check-overload-typing" + priority = -1 + msgs = { + "C4749": ( + "BALH. ", + "overloaded-function-returns-none", + "BLAH.", + ), + } + options = ( + ( + "ignore-overloaded-function-returns-none", + { + "default": False, + "type": "yn", + "metavar": "", + "help": "blah.", + }, + ), + ) + def __init__(self, linter=None): + super(TypingOverloadReturnNone, self).__init__(linter) + + #Test on tables + def visit_classdef(self,node): + if node.name.endswith("Client"): + overloaded_functions = [] + all_functions = {} + for i in node.body: + if isinstance(i, astroid.FunctionDef): + if 'typing.overload' in i.decoratornames(): + overloaded_functions.append(i) + else: + all_functions.update({i.name:i}) + for func in overloaded_functions: + if func.name in all_functions.keys(): + if (isinstance(func, astroid.AsyncFunctionDef) and not isinstance(all_functions.get(func.name), astroid.AsyncFunctionDef)) \ + or (not isinstance(func, astroid.AsyncFunctionDef) and isinstance(all_functions.get(func.name), astroid.AsyncFunctionDef)): + self.add_message( + msgid="overloaded-function-returns-none", node=func, confidence=None + ) + + # if a linter is registered in this function then it will be checked with pylint def register(linter): linter.register_checker(ClientsDoNotUseStaticMethods(linter)) @@ -1937,6 +1983,7 @@ def register(linter): linter.register_checker(CheckNamingMismatchGeneratedCode(linter)) linter.register_checker(CheckAPIVersion(linter)) linter.register_checker(CheckEnum(linter)) + linter.register_checker(TypingOverloadReturnNone(linter)) # disabled by default, use pylint --enable=check-docstrings if you want to use it