0
import turtle 


class Polygon: 
    def __init__(self,sides,name,size=100,color='black',line_thickness=3):
        self.sides=sides
        self.name=name 
        self.size=size
        self.color=color
        self.line_thickness=line_thickness
        self.interior_angles=(self.sides-2)*180
        self.angle=self.interior_angles/self.sides
    
    def draw(self):
        turtle.color(self.color)
        turtle.pensize(self.line_thickness)
        for i in range(self.sides): 
            turtle.forward(self.size)
            turtle.right(180-self.angle)
        turtle.done()

square=Polygon(4,'Square')
square.draw()

Considering the code above, operating in VSCODE, I am wondering how to get rid of all the 'pylint' errors that continue to pop up which suggest something similar to the following:

Module 'turtle' has no 'color' member (pylint no-member)

Although the code executes just fine, it is unsettling to continue having to look at the error lines and I am wondering if there is a solution to this. Thanks for you time!

  • There are lots of ways to suppress the error message. Is that what you seek? – Dennis Sparrow Jul 10 '20 at 20:17
  • Yes pretty much! Is there a way to suppress this particular error message but still be able to receive notification about other errors? or is this not possible? Thanks Dennis – John Feldhausen Jul 10 '20 at 21:47
  • Dennis Sparrow, can you help? – John Feldhausen Jul 10 '20 at 23:12
  • Yes, you can limit suppression to one particular check and you can control the scope from one line of code to all Pylint operations for your installation. You should be able to find out how in the [Pylint documentation](http://pylint.pycqa.org/en/latest/faq.html#message-control) or [How do I disable a Pylint warning?](https://stackoverflow.com/questions/4341746/how-do-i-disable-a-pylint-warning). – Dennis Sparrow Jul 10 '20 at 23:14

1 Answers1

0

Rather than suppress the error message, why not fix the code? Turtle presents two APIs, a functional one and an object-oriented one. The functional one is derived from the object-oriented one at load time. Analysis tools can't look inside the source library file and see the functional signatures.

Since you're defining your own Polygon object, I don't see why you're not using the object-oriented interface to turtle. The import I use below blocks the functional interface and only allows access to the object-oriented one:

from turtle import Screen, Turtle

class Polygon:
    def __init__(self, sides, name, size=100, color='black', line_thickness=3):
        self.sides = sides
        self.name = name
        self.size = size
        self.color = color
        self.line_thickness = line_thickness
        self.interior_angles = (self.sides - 2) * 180
        self.angle = self.interior_angles / self.sides

    def draw(self):
        turtle.color(self.color)
        turtle.pensize(self.line_thickness)

        for _ in range(self.sides):
            turtle.forward(self.size)
            turtle.right(180 - self.angle)

screen = Screen()
turtle = Turtle()

square = Polygon(4, 'Square')
square.draw()

screen.exitonclick()

Note the subtle changes to the code to accommodate the object-oriented API. Now try your analysis of the code to see if this solves your problem.

cdlane
  • 40,441
  • 5
  • 32
  • 81
  • Being new to python, this was one of my first attempts at using OOP. Could you explain if your turtle=Turtle(), corresponds to the turtle.color() or turtle.pensize(). Basically, does the code turtle=Turtle() in the main block relate to that which is given in your functions? – John Feldhausen Jul 14 '20 at 03:17
  • Thank you so much by the way for your answer – John Feldhausen Jul 14 '20 at 03:18
  • @JohnFeldhausen, in your code, when you said `turtle.color()`, you were talking about the `color()` *function* in the *turtle module* you imported. When I say `turtle.color()` I'm talking about the `color()` *method* of the `turtle` instance created by `turtle = Turtle()`. I realize this can be confusing, which is why I use the `import` I do, to shut out the functional interface and focus on the object-oriented one. – cdlane Jul 14 '20 at 04:35