Open In App

NO Quality Assurance (noqa) in Python

Last Updated : 17 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Well if you are someone who has just started with Python then you would most likely be not aware of this feature. Even if you are an experienced programmer then you might not be aware of this nifty little feature. This is going to be a short and simple but very useful article. So, what exactly is noqa. NOQA stands for NO Quality Assurance

noqa = NO-QA (NO Quality Assurance)

What this typically means is that if you have any warning in your IDE, then if you add a comment as # noqa at the end of the line then the warning will be ignored by the IDE. This thing might seem very trivial but it can be extremely useful in a production environment where there are certain configurations set at the project level, which prevents a developer from pushing code to VCS which has warnings.

Obviously, Sometimes the IDE fails to understand certain coding styles, like if you do an import in the __init__.py of a package and you never use it in the same file. The only reason why you imported that was so that it is accessible by any other developer who will be consuming your package.

First, We will be creating a python package called demo_noqa. The directory should contain two files, __init__.py, and check.py. Your directory structure should look something like this.

Directory structure

Now, go to check.py and simply create a function called printf(). You can use the below code sample.

Python3

def printf():
    print("*\n**\n")

                    

Now, go to __init__.py and simply import printf it from check.py. You can look into the below code sample

Python3

from .check import printf

                    

Now, just save the file. You will see that you will get a warning saying printf imported but never used. Here, below is the example

Warning example

Notice the while line below printf. This is a warning. Now, if you simply add # noqa at the end of the line, the warning will be suppressed. Here, below is an example of the same.

Suppressed warning

Notice that the bulb icon is gone and the white line too. This is how noqa is used. You might find it very trivial if you are a beginner but trust me, once you get into the real world jobs and you will start to work on the production level codes, you will end up using noqa quite frequently.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads