Open
Description
PyLint generates a lot of errors in a program using the turtle module: pylint-dev/pylint#1928 and microsoft/vscode-python#1056
The following brain fixes this. It uses the same method as the turtle module to generate stubs for astroid to parse.
brain_turtle.py
import astroid
def register(linter):
pass
def transform():
import turtle
def _make_global_funcs(functions, cls):
funcs = []
for methodname in functions:
method = getattr(cls, methodname)
paramslist, argslist = turtle.getmethparlist(method)
if paramslist == "": continue
funcs.append(f"def {methodname}{paramslist}: return")
return funcs
funcs = []
funcs.extend(_make_global_funcs(turtle._tg_screen_functions, turtle._Screen))
funcs.extend(_make_global_funcs(turtle._tg_turtle_functions, turtle.Turtle))
return astroid.parse('\n'.join(funcs))
astroid.register_module_extender(astroid.MANAGER, "turtle", transform)