A Practical Guide in understanding Git Branch and Conflict resolution during merge
Introduction In this guide, We will learn about branching, handling conflict…
December 02, 2018
Pylint is an excellent tool to have good quality code. This post is not about how pylint works. Lets see most common pylint errors:
When you are defining methods in python, its necessary to give them some text help what the function is all about. Example:
def say_hello():
print("Hello")
Running pylint on this method will give you this error. To solve this:
def say_hello():
"""
This function prints hello
"""
print("Hello")
This error happens in class methods. You have a class and some methods, but in this method you are not using ‘self’ object which is usually a reference to the current instance of the class.
class Hello:
def hey(self):
print('hey')
In above method, ‘self’ is unused. And, you will get this error: pylint: Method could be a function (no-self-use)
There are two solutions to this:
class Hello:
@classmethod
def hey(cls):
print('hey')
You have some custom modules and trying to run pylint. Pylint complains about unknown modules. What to do? To solve this, you need to edit your .pylintrc file,
In init-hook, append your module paths as:
init-hook='import sys; sys.path.append('./modules/hardening_base');sys.path.append('./modules/script_collector');
Where, modules/hardening_base is path of one of my module from root folder of project.
Now run pylint, and error is gone.
In your main file, you are probably initializing an object without a function. Define a method.
def my_method():
print('hello')
if __name__ == "__main__":
my_method()
args is an array and I want to put an if condition to check if length is greater than 0.
if len(args) > 0:
# do something
In python 3, this can be re-written as:
if args:
# do something
Your source code line is this much character long. And, recommended configuration says you should have max of 100 character long line. There are two solution:
Break your line to multiple lines
arr = [a, b, c]
to
arr = [
a,
b,
c
]
a = 'abc abc abc abc'
to
a = 'abc abc '\
'abc abc'
a.call(a, b, c, d)
to
a.call(
a,
b,
c,
d)
Edit your .pylintrc file: look for [FORMAT] section
See setting:
max-line-length=100
change it to some greater value. But, this is not recommended way. You should break your lines into multiple lines.
There is one setting which can disable certain checks that pylint runs. You can disable few checks as per your need.
Edit your .pylintrc file: Look for [MESSAGES CONTROL]
See disable setting
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
You can include the pylint error here, which mentions name of check, and run pylint again.
Introduction In this guide, We will learn about branching, handling conflict…
Its good to write unit tests cases, and this part is mostly forgotten by…
To download this code from git: See: Gyanblog Github
I was testing a bug where a field was limited to 255 characters only. I needed…
Introduction In our previous post How to configure Grafana on docker, we saw how…
After 2 days, there was my demo. I deployed my nodejs code on lambda function…
In this post, we will see some of the frequently used concepts/vocabulary in…
System design interview is pretty common these days, specially if you are having…
Introduction You are given an array of integers with size N, and a number K…
Graph Topological Sorting This is a well known problem in graph world…
Problem Statement Given a Binary tree, print out nodes in level order traversal…
Problem Statement Given an array nums of n integers and an integer target, are…