PyCharm fake syntax error using turtle

The code below works fine, however PyCharm complains about a syntax error in forward(100)

#!/usr/bin/python
from turtle import *

forward(100)

done()

      

Since turtle

stanrd is a library, I don't think I need to do any additional configuration, right?

enter image description here

+3


source to share


2 answers


The function forward()

is available for import by specifying __all__

the turtle

corresponding part from the source code in the module :

_tg_turtle_functions = [..., 'forward', ...]
__all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions +
           _tg_utilities + _math_functions)

      

Currently pycharm cannot see the objects listed in the module list __all__

and therefore marks them as unresolved reference

. It has a bugtracker problem:

Make a function from a method: update __all__ if it exists to use as a noticed import

See also: Can someone explain __all__ in Python?




FYI, you can add a comment noinspection

to tell Pycharm not to mark it as an unresolved link:

from turtle import *

#noinspection PyUnresolvedReferences
forward(100)

done()

      

Or disable scanning for a specific area .




And of course, strictly speaking, you should follow PEP8 and avoid wildcard imports :

import turtle

turtle.forward(100)
turtle.done()

      

+10


source


Another solution would be to explicitly create the object Turtle

. Then the autocomplete works as it should and things become a little more explicit.

import turtle

t = turtle.Turtle()

t.left(100)
t.forward(100)

turtle.done()

      



or

from turtle import Turtle

t = Turtle()

      

0


source







All Articles