On Saturday 28 August 2010 12:48:20 Jakub Zytka wrote: > Hello > > I'm getting false positives in a, I confess, quite bizzare case > (testcase below). Short story is that I have some dynamically generated > python extension module (C++). I also have lots of tests in python and > some of them are using the extension module. I run pylint and pytest on > these tests and everything is ok up to a point: > sometimes I'm unable to deliver this C++ extension module. In such case > some of the tests fail pytest/pylint verification due to unresolved > imports. I decided it's the best to use 'stub' extension module, > written in python, when it is not possible to provide the C++ based > one. Since the C++ module is dynamically generated and it contains lots > of classes/functions it is not feasible to define then in the stub > module. Instead, I decided to write a generic python module, which > defines "everything". This works fine with python and pytest, but > pylint still complains. > > I don't know if this behavior can be fixed in pylint. Any ideas how to > deal with this problem (maybe mod.py could be written differently?)? > > Testcase: > files: > > ------ mod.py ------- > import sys > > class FakeModule: > def __getattr__(self, x): > return None > > sys.modules[__name__] = FakeModule() > > ------ test.py ------- > from mod import Whatever > import mod > a = mod.Spam > if Whatever is None and a is None: > print 'wow! this works' > > "python test.py" output: > wow! this works > > pylint's output: > > ************* Module test > E0611: 1: No name 'Whatever' in module 'mod' > E1101: 3: Module 'mod' has no 'Spam' member
pylint is a static code checker, so mod.py will not be executed, hence no modification of sys.modules. But the --init-hook option (see pylint --long-help) might help: --init-hook=<code> Python code to execute, usually for sys.path manipulation such as pygtk.require(). $ pylint --init-hook='print "QSDFSD"' example.py QSDFSD [...] -- Emile Anclin <emile.anc...@logilab.fr> http://www.logilab.fr/ http://www.logilab.org/ Informatique scientifique & et gestion de connaissances _______________________________________________ Python-Projects mailing list Python-Projects@lists.logilab.org http://lists.logilab.org/mailman/listinfo/python-projects