You may come across certain messages PyLint returns to you, you don’t agree with. The purpose of this lesson is to show you a few examples, where this can happen.
Using PyLint Feedback to Improve Your Code
And at any time, you can just rerun Pylint, right? There’s no harm in that. It’s not going to execute your program, it’s not going to do anything. It’s just going to inspect your code. All right, so
Invalid class name "car".
00:38 I think that’s also interesting because, again, here what we want is an uppercase class name for this class if we want to follow the PEP 8 style guide, and that’s a very good recommendation, right?
now we should actually get a new problem that tells me that
car isn’t defined, right? Because now
car doesn’t exist anymore. I just renamed the class from lowercase
car to uppercase
Car. Or like, it starts with an uppercase character now.
And now this code is broken. And Pylint told me about this, which is kind of nice. All right, so now the code is actually terrible, right? Like, now our score is really bad because we have some critical error in here that means the program wouldn’t actually run. So we have, like, a real error here—it’s not a warning, it’s a real error. All right, so let’s run this again. Okay,
Missing class docstring. All right, I’m just going to put a terrible docstring here,
"""Example class""". Right? It’s not a real good docstring. Okay, now we’re getting into some territory. So here, let me refresh this.
01:50 We’re getting into some territory where this is very, sort of, subjective feedback, right? So now it’s telling us that, “Hey! This class doesn’t have enough public methods.” And, I mean, that’s true, but then we’re sort of… You know, this might still make sense given the context of the program.
02:07 Pylint is very opinionated in that sense, and it’s going to tell you, it’s going to point out some things that you might disagree with. And that’s where it’s important to look into how to suppress some of these so that you can kind of tweak it and tune it to your liking.
02:24 If you’re doing this intentionally, then you might not want to see that error. And to a certain degree, that’s why I prefer Flake8, because Flake8 is only pointing out code style issues and things that are just not a good idea to do, right?
02:38 Like, it’s not going to tell you, “Hey, you didn’t define enough public methods on a class,” but it’s going to tell you that, you know, you made a formatting mistake or you’re doing something that is not recommended.
03:05 And, you know, this might be a good thing, it might be a bad thing. Like actually, I think for someone who’s just starting out to write Python or they want to get better at their Python—it can be a very helpful thing.
I actually used Pylint a lot in the past. And then, well, since the last couple of years, I switched over to Flake8 for pretty much that reason. So, you can always run both too, right? And that’s always a possibility. Anyway, let’s fix some of the remaining stuff here. Okay, I’ve got
Invalid constant name 'my_car'. Okay, because we’re not using that for anything, right? Because…
"""An example function""". Okay, we did that. So now this is telling us about a missing or unused argument in this function definition here. As you can see here, we define
car2, but we’re never really using it in the function. And again, this might be intentional or this might not be intentional, and this is a good example to show you how we can suppress these errors in Pylint as well.
Become a Member to join the conversation.