pylint-twisted
is Pylint plugin for improving code
analysis when editing code using Twisted.
Inspired by pylint-django.
-
Recognize generator with
defer.inlineCallbacks
decorator returns Deferred object. Say you have the following code:from twisted.internet import defer @defer.inlineCallbacks def func(): yield some_other_func() def normal_deferred_func(): d = foo() d.addCallback(lambda _: None) d.addErrback(lambda _: None)
Normally, pylint will throw errors like:
E: 1,0: No name 'addCallback' in generator 'func' E: 2,0: No name 'addErrback' in generator 'func'
As pylint builds it's own abstract syntax tree,
pylint-twisted
will translate the@defer.inlineCallbacks
decorator to return Deferred object instead of a generator, so pylint can continue checking your code. -
Recognize
twisted.internet.reactor
module. Say you have the following code:from twisted.internet import reactor def foo(): return reactor.seconds()
Normally, pylint will throw errors like:
E: 1,0: No name 'seconds' in module 'reactor'
twisted reactor modules actually imports different modules base on the OS type at runtime.
pylint-twisted
will run the imports to let pylint know the actual reactor module, so pylint can continue checking your code.
Ensure pylint-twisted
is installed and on your path, and then run pylint using
pylint-twisted as a plugin.
pip install pylint-twisted
pylint --load-plugins pylint_twisted [..your module..]
Pull requests are always welcome. Here's an outline of the steps you need to prepare your code.
- git clone https://github.com/jonnyyu/pylint-twisted.git
- cd pylint-twisted
- mkvirtualenv pylint-twisted
- pip install -r dev-requirements.txt
- git checkout -b MY-NEW-FIX
- Hack away
- Make sure everything is green by running
tox
- git push origin MY-NEW-FIX
- Create a pull request