[Twisted-Python] Work around pyflakes errors
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
On 3 Mar, 04:59 pm, adi@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
On 10 March 2014 00:04,
Cool. I always forget about the other APIs since `namedAny` works for anything. :) `namedModule` seems like a great fit here.
Jean-Paul
I have implemented a requireModule helper to handle the try/except ImporError code which would create a lot of code duplication when used with `namedAny` https://twistedmatrix.com/trac/ticket/7014 If 7014 is accepted I could go and update existing pyflakes reviews to use the new code. -- Adi Roiban
participants (2)
-
Adi Roiban
-
exarkun@twistedmatrix.com