Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixture for ValueError.message to modernize #261

Open
CarstenGrohmann opened this issue Nov 13, 2022 · 0 comments
Open

Add fixture for ValueError.message to modernize #261

CarstenGrohmann opened this issue Nov 13, 2022 · 0 comments

Comments

@CarstenGrohmann
Copy link

Bug report

Please extend the modernize tool to display a warning when ValueError.message is used, or replace the message attribute
e.g. with str(<exception>), since ValueError.message no longer exists in Python 3.

Reproducer

$ cat example.py2
#!/usr/bin/env python2.7
try:
   raise ValueError('Foo')
except ValueError as e:
   print "Caught: %s" % e.message

$ modernize example.py2 
Loading the following fixers:
   fissix.fixes.fix_apply  (apply)
   fissix.fixes.fix_except  (except)
   fissix.fixes.fix_exec  (exec)
   fissix.fixes.fix_execfile  (execfile)
   fissix.fixes.fix_exitfunc  (exitfunc)
   fissix.fixes.fix_funcattrs  (funcattrs)
   fissix.fixes.fix_has_key  (has_key)
   fissix.fixes.fix_idioms  (idioms)
   fissix.fixes.fix_long  (long)
   fissix.fixes.fix_methodattrs  (methodattrs)
   fissix.fixes.fix_ne  (ne)
   fissix.fixes.fix_numliterals  (numliterals)
   fissix.fixes.fix_operator  (operator)
   fissix.fixes.fix_paren  (paren)
   fissix.fixes.fix_reduce  (reduce)
   fissix.fixes.fix_renames  (renames)
   fissix.fixes.fix_repr  (repr)
   fissix.fixes.fix_set_literal  (set_literal)
   fissix.fixes.fix_standarderror  (standarderror)
   fissix.fixes.fix_sys_exc  (sys_exc)
   fissix.fixes.fix_throw  (throw)
   fissix.fixes.fix_tuple_params  (tuple_params)
   fissix.fixes.fix_types  (types)
   fissix.fixes.fix_ws_comma  (ws_comma)
   fissix.fixes.fix_xreadlines  (xreadlines)
   libmodernize.fixes.fix_basestring  (basestring)
   libmodernize.fixes.fix_dict_six  (dict_six)
   libmodernize.fixes.fix_file  (file)
   libmodernize.fixes.fix_filter  (filter)
   libmodernize.fixes.fix_import  (import)
   libmodernize.fixes.fix_imports_six  (imports_six)
   libmodernize.fixes.fix_input_six  (input_six)
   libmodernize.fixes.fix_int_long_tuple  (int_long_tuple)
   libmodernize.fixes.fix_itertools_imports_six  (itertools_imports_six)
   libmodernize.fixes.fix_itertools_six  (itertools_six)
   libmodernize.fixes.fix_map  (map)
   libmodernize.fixes.fix_metaclass  (metaclass)
   libmodernize.fixes.fix_next  (next)
   libmodernize.fixes.fix_print  (print)
   libmodernize.fixes.fix_raise  (raise)
   libmodernize.fixes.fix_raise_six  (raise_six)
   libmodernize.fixes.fix_unichr  (unichr)
   libmodernize.fixes.fix_unicode_type  (unicode_type)
   libmodernize.fixes.fix_urllib_six  (urllib_six)
   libmodernize.fixes.fix_xrange_six  (xrange_six)
   libmodernize.fixes.fix_zip  (zip)
Applying the following explicit transformations:
   (None)

RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored example.py2
--- example.py2	(original)
+++ example.py2	(refactored)
@@ -1,5 +1,6 @@
#!/usr/bin/env python2.7
+from __future__ import print_function
try:
    raise ValueError('Foo')
except ValueError as e:
-    print "Caught: %s" % e.message
+    print("Caught: %s" % e.message)
RefactoringTool: Files that need to be modified:
RefactoringTool: example.py2

Example of an expected result

--- example.py2	(original)
+++ example.py2	(refactored)
@@ -2,4 +2,4 @@
 try:
     raise ValueError('Foo')
 except ValueError as e:
-    print "Caught: %s" % e.message
+    print("Caught: %s" % str(e))

My environment

  • up-to-date ArchLinux on x86_64
  • Python 3.10.8 (main, Oct 13 2022, 21:13:48) [GCC 12.2.0]
  • modernize 0.8.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant