[Twisted-Python] Work around pyflakes errors

Adi Roiban adi at roiban.ro
Mon Mar 3 09:59:01 MST 2014


I would like to see twisted code base free of pyflakes errors.

In this way, when someone sees pyflakes errors in his/her branch will know
for sure that those errors are generated by changes in that branch. Also
developers could run pyflakes on local computers, before sending a patch
and have instance feedback for pyflakes errors.

One problem is that pyflakes will complain about unused imports.

JP suggested a fix for that and I have created a ticket:
https://twistedmatrix.com/trac/ticket/7014

I am not sure how the suggested requireModule("OpenSSL") style API should
work, but in the same comment, JP suggested to use 'namedAny' to get the
same effect as the unused import.

My problem with namedAny is that it does not raise ImportError ... but
rather ModuleNotFound or ObjectNotFound.

But I found 'namedModule' which raise ImportError

Here is an example of namedModule usage which should work around pyflakes
errors.

Old code:

try:
    import threading
    threading  # Silence the linter.
except ImportError:
    self.assertFalse(Platform().supportsThreads())

New code

try:
    namedModule('threading')
except ImportError:
    self.assertFalse(Platform().supportsThreads())

What do you think, is namedModule usage acceptable or we should work at
implementing the requireModule("OpenSSL") API?

Thanks!
-- 
Adi Roiban
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140303/a87a1bed/attachment.html>


More information about the Twisted-Python mailing list