PyCQA / modernize

Modernizes Python code for eventual Python 3 migration. Built on top of fissix (a fork of lib2to3)
https://modernize.readthedocs.org/
Other
353 stars 51 forks source link

Raise with string and format operator is fixed incorrectly #192

Open dwvisser opened 5 years ago

dwvisser commented 5 years ago

This is similar to issue #180, which appears to have been closed without any justification given. Here's the relevant portion of the output of python-modernize (v0.7) which illustrates the bug:

--- test_modernize_formatted_raise.py   (original)
+++ test_modernize_formatted_raise.py   (refactored)
@@ -1,4 +1,4 @@
 def hello(name, language):
     if language is None:
-        raise('Language for %s not defined' % name)
+        raise 'Language for %s not defined'
     pass
dwvisser commented 5 years ago

I see that in Python 3 that raise has been changed to only accept a single argument, which must be an expression that resolves to something that is BaseException or derived from it. I think that python-modernize should emit warning messages at least on these refactorings.

ngie-eign commented 5 years ago

Wow. Yeah, that's really broken code :/...