How can I tell Pychecker to ignore an imported library?
One of the modules I import into my python project triggers lots of warnings under Pychecker. Fixing up this external module isn't really an option, so I want to tell Pychecker to ignore it.
Does开发者_StackOverflow社区 anyone know how to do this? I'm sure it's possible, and probably quite simple, but after trawling Google for a while I've not found any documentation or examples.
Thanks, Sam
Edit: I can't tag this with 'pychecker' unfortunately as that tag doesn't exist yet and my rep is too low to create.
Edit 2 Bonus extra question: does pychecker check ignored modules anyway, and just not print anything it finds? or do you get some speedup by ignoring some modules?
Per the docs,
If you want to suppress warnings on a module/function/class/method, you can define a suppressions dictionary in .pycheckrc. Examples of keys are: 'module', 'module.function', 'module.class', 'module.class.method', etc.etc.
IOW, in your .pycheckrc, if the troublesome module is named foobar
, you'll have
suppressions = {'foobar': '...'}
where the ...
means, all the suppress options you want. Use pychecker -h
to get a list of all the options; I think 'limit=0'
will do what you're asking for (show a max of 0 warnings for that module, i.e., none;-), but you may want to be a bit more selective (after all you only have to write this once and for all in .pycheckrc
, not on every spot from which you're calling pychecker
... which is the convenience of the pycheckrc approach!).
I've found another option - you can blacklist using the -b flag. Eg
python pychecker.py -b list,of,modules,to,ignore
I'm not sure, but I think this checks the imported modules anyway, but just doesn't print the warnings. It certainly doesn't seem any faster with the -b flag than without - though at least the warnings are gone :-)
On the bonus extra question:
- pychecker always imports the files you pass it, which causes it to import whatever those import. This is just like Python. This is a first pass in pychecker.
- Then pychecker will actually go through the loaded modules, disassemble the code, and run through all the opcodes. This is a second pass.
- In both cases, it tracks all warnings generated even by ignored modules. Then it filters out those warnings before showing them.
I am considering if it is worth it to change pychecker to not even look at blacklisted modules at all, or make it possible to only disassemble the one file (for integration in an editor for example).
精彩评论