Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to tell pylint to ignore certain imports?

Tags:

python

pylint

I'm developing software for Windows with Python. I am developing on Linux, and I am using Pylint to check my code. I can't get rid of the error:

F| Unable to import '_winreg'    

This is obvious - Python on Linux does not have this module.

So, what do I have to put in my .pylintrc to ignore this error?

Thanks in advance, Oz

EDIT:

Documentation says:

:F0401: *Unable to import %r*   Used when pylint has been unable to import a module. 

Now I need to find how to use it ...

Partial solution:

pylint --disable=F0401 <filename> 

I am still looking for a way to do via .pylintrc.

like image 510
oz123 Avatar asked Mar 07 '12 13:03

oz123


People also ask

How do you ignore specific Pylint errors?

This may be done by adding # pylint: disable=some-message,another-one at the desired block level or at the end of the desired line of code.

How do you make Pylint ignore?

you can ignore it by adding a comment in the format # pylint: disable=[problem-code] at the end of the line where [problem-code] is the value inside pylint(...) in the pylint message – for example, abstract-class-instantiated for the problem report listed above.

How do I skip a file in Pylint?

The solution was to include --disable=file-ignored in the Pylint command options. It took way too long to figure this out; there shouldn't be a file-ignored error when you explicitly ignore a file. More ideally, put it in a pylintrc config file, not in a command option.

How do I ignore a folder in Pylint?

You can not give a path, but only the "basename" of the directory. E.g., use --ignore=lib instead of --ignore-=appengine-toolkit/gaetk/lib . The problem is you will ignore all directories named lib .


1 Answers

Just run into this as well with the following code:

 8: if os.name == 'nt':  9:    import msvcrt 10: else: 11:    import fcntl 

pylint failed the build with this error:

E:  9, 4: Unable to import 'msvcrt' (import-error) 

The solution is available since pylint 0.10:

 9:    import msvcrt  # pylint: disable=import-error 
like image 72
anatoly techtonik Avatar answered Sep 29 '22 11:09

anatoly techtonik