Suppress warnings in PyDev

I use the following at the beginning of all modules in my Python project:

import setup_loggers 

setup_loggers is a module that does just that. The import statement ensures that no matter which module is loaded first, the loggers are configured and ready.

However, since I do not use the setup_loggers module later in the file, I get a PyDev warning (a small yellow marker). I get this warning for all my modules, so it blocks me from viewing other warnings in the PyDev package explorer.

Is there a way to suppress a warning for a specific line ( import line above) in PyDev?
Any other ideas on how to overcome this annoyance?

+6
source share
1 answer

In PyDev, whenever there is an error in a line, you can press Ctrl + 1, and it will show the ability to ignore this warning in this line (in this case, it will add a comment: # @UnusedImport - which you can add manually - in this line and that the error / warning will be ignored).

Now, for a better strategy for you (so you don't have to import this module everywhere): in Python, when you import a package, parents will be imported earlier.

i.e:.

 /my_project /my_project/__init__.py /my_project/submodule.py /my_project/package /my_project/package/__init__.py 

When importing my_project.submodule or my_project.package, you will first need to import (and execute) the code in /my_project/__init__.py

So, the best strategy for you would be just adding this import to /my_project/__init__.py (and whenever any submodule is imported, the registrars will already be configured).

It just doesn't work if you have a collection of files that are scattered in the root directory of PYTHONPATH, and in a file that you execute as your __main__ (since it will not import this file, it will simply receive its contents and execute it - but any time that this file imports something from / my _project, everything will be installed).

+25
source

Source: https://habr.com/ru/post/896290/


All Articles