Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pylint] Overload functions cannot switch from implementation format (async/sync) #23936

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions scripts/pylint_custom_plugin/pylint_guidelines_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<y_or_n>",
"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))
Expand All @@ -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
Expand Down