[Twisted-Python] Work around pyflakes errors
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Sun Mar 9 16:04:44 MDT 2014
On 3 Mar, 04:59 pm, adi at roiban.ro wrote:
>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?
Cool. I always forget about the other APIs since `namedAny` works for
anything. :) `namedModule` seems like a great fit here.
Jean-Paul
More information about the Twisted-Python
mailing list