__init__.py 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import sys
  2. from lib2to3 import refactor
  3. # The following fixers are "safe": they convert Python 2 code to more
  4. # modern Python 2 code. They should be uncontroversial to apply to most
  5. # projects that are happy to drop support for Py2.5 and below. Applying
  6. # them first will reduce the size of the patch set for the real porting.
  7. lib2to3_fix_names_stage1 = set([
  8. 'lib2to3.fixes.fix_apply',
  9. 'lib2to3.fixes.fix_except',
  10. 'lib2to3.fixes.fix_exec',
  11. 'lib2to3.fixes.fix_exitfunc',
  12. 'lib2to3.fixes.fix_funcattrs',
  13. 'lib2to3.fixes.fix_has_key',
  14. 'lib2to3.fixes.fix_idioms',
  15. # 'lib2to3.fixes.fix_import', # makes any implicit relative imports explicit. (Use with ``from __future__ import absolute_import)
  16. 'lib2to3.fixes.fix_intern',
  17. 'lib2to3.fixes.fix_isinstance',
  18. 'lib2to3.fixes.fix_methodattrs',
  19. 'lib2to3.fixes.fix_ne',
  20. # 'lib2to3.fixes.fix_next', # would replace ``next`` method names
  21. # with ``__next__``.
  22. 'lib2to3.fixes.fix_numliterals', # turns 1L into 1, 0755 into 0o755
  23. 'lib2to3.fixes.fix_paren',
  24. # 'lib2to3.fixes.fix_print', # see the libfuturize fixer that also
  25. # adds ``from __future__ import print_function``
  26. # 'lib2to3.fixes.fix_raise', # uses incompatible with_traceback() method on exceptions
  27. 'lib2to3.fixes.fix_reduce', # reduce is available in functools on Py2.6/Py2.7
  28. 'lib2to3.fixes.fix_renames', # sys.maxint -> sys.maxsize
  29. # 'lib2to3.fixes.fix_set_literal', # this is unnecessary and breaks Py2.6 support
  30. 'lib2to3.fixes.fix_repr',
  31. 'lib2to3.fixes.fix_standarderror',
  32. 'lib2to3.fixes.fix_sys_exc',
  33. 'lib2to3.fixes.fix_throw',
  34. 'lib2to3.fixes.fix_tuple_params',
  35. 'lib2to3.fixes.fix_types',
  36. 'lib2to3.fixes.fix_ws_comma', # can perhaps decrease readability: see issue #58
  37. 'lib2to3.fixes.fix_xreadlines',
  38. ])
  39. # The following fixers add a dependency on the ``future`` package on order to
  40. # support Python 2:
  41. lib2to3_fix_names_stage2 = set([
  42. # 'lib2to3.fixes.fix_buffer', # perhaps not safe. Test this.
  43. # 'lib2to3.fixes.fix_callable', # not needed in Py3.2+
  44. 'lib2to3.fixes.fix_dict', # TODO: add support for utils.viewitems() etc. and move to stage2
  45. # 'lib2to3.fixes.fix_execfile', # some problems: see issue #37.
  46. # We use a custom fixer instead (see below)
  47. # 'lib2to3.fixes.fix_future', # we don't want to remove __future__ imports
  48. 'lib2to3.fixes.fix_getcwdu',
  49. # 'lib2to3.fixes.fix_imports', # called by libfuturize.fixes.fix_future_standard_library
  50. # 'lib2to3.fixes.fix_imports2', # we don't handle this yet (dbm)
  51. # 'lib2to3.fixes.fix_input', # Called conditionally by libfuturize.fixes.fix_input
  52. 'lib2to3.fixes.fix_itertools',
  53. 'lib2to3.fixes.fix_itertools_imports',
  54. 'lib2to3.fixes.fix_filter',
  55. 'lib2to3.fixes.fix_long',
  56. 'lib2to3.fixes.fix_map',
  57. # 'lib2to3.fixes.fix_metaclass', # causes SyntaxError in Py2! Use the one from ``six`` instead
  58. 'lib2to3.fixes.fix_next',
  59. 'lib2to3.fixes.fix_nonzero', # TODO: cause this to import ``object`` and/or add a decorator for mapping __bool__ to __nonzero__
  60. 'lib2to3.fixes.fix_operator', # we will need support for this by e.g. extending the Py2 operator module to provide those functions in Py3
  61. 'lib2to3.fixes.fix_raw_input',
  62. # 'lib2to3.fixes.fix_unicode', # strips off the u'' prefix, which removes a potentially helpful source of information for disambiguating unicode/byte strings
  63. # 'lib2to3.fixes.fix_urllib', # included in libfuturize.fix_future_standard_library_urllib
  64. # 'lib2to3.fixes.fix_xrange', # custom one because of a bug with Py3.3's lib2to3
  65. 'lib2to3.fixes.fix_zip',
  66. ])
  67. libfuturize_fix_names_stage1 = set([
  68. 'libfuturize.fixes.fix_absolute_import',
  69. 'libfuturize.fixes.fix_next_call', # obj.next() -> next(obj). Unlike
  70. # lib2to3.fixes.fix_next, doesn't change
  71. # the ``next`` method to ``__next__``.
  72. 'libfuturize.fixes.fix_print_with_import',
  73. 'libfuturize.fixes.fix_raise',
  74. # 'libfuturize.fixes.fix_order___future__imports', # TODO: consolidate to a single line to simplify testing
  75. ])
  76. libfuturize_fix_names_stage2 = set([
  77. 'libfuturize.fixes.fix_basestring',
  78. # 'libfuturize.fixes.fix_add__future__imports_except_unicode_literals', # just in case
  79. 'libfuturize.fixes.fix_cmp',
  80. 'libfuturize.fixes.fix_division_safe',
  81. 'libfuturize.fixes.fix_execfile',
  82. 'libfuturize.fixes.fix_future_builtins',
  83. 'libfuturize.fixes.fix_future_standard_library',
  84. 'libfuturize.fixes.fix_future_standard_library_urllib',
  85. 'libfuturize.fixes.fix_input',
  86. 'libfuturize.fixes.fix_metaclass',
  87. 'libpasteurize.fixes.fix_newstyle',
  88. 'libfuturize.fixes.fix_object',
  89. # 'libfuturize.fixes.fix_order___future__imports', # TODO: consolidate to a single line to simplify testing
  90. 'libfuturize.fixes.fix_unicode_keep_u',
  91. # 'libfuturize.fixes.fix_unicode_literals_import',
  92. 'libfuturize.fixes.fix_xrange_with_import', # custom one because of a bug with Py3.3's lib2to3
  93. ])