Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- evalkit_cambrian/lib/python3.10/lib2to3/PatternGrammar3.10.16.final.0.pickle +3 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__init__.py +1 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_apply.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_asserts.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_basestring.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_buffer.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_dict.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_except.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_execfile.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_filter.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_funcattrs.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_future.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_getcwdu.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_idioms.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_import.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_imports2.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_input.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_intern.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_isinstance.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_itertools.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_itertools_imports.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_long.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_map.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_metaclass.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_methodattrs.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_ne.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_next.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_numliterals.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_operator.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_paren.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_print.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_raise.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_raw_input.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_reduce.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_renames.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_repr.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_set_literal.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_sys_exc.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_throw.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_tuple_params.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_types.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_unicode.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_urllib.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_ws_comma.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_xrange.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_xreadlines.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_zip.cpython-310.pyc +0 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/fix_apply.py +68 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/fix_asserts.py +34 -0
- evalkit_cambrian/lib/python3.10/lib2to3/fixes/fix_except.py +93 -0
evalkit_cambrian/lib/python3.10/lib2to3/PatternGrammar3.10.16.final.0.pickle
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:36ee934395b9209737b13893ddaff05fad8e239c2fdfac29d401d3fceeb30768
|
| 3 |
+
size 1225
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Dummy file to make this directory a package.
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_apply.cpython-310.pyc
ADDED
|
Binary file (1.91 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_asserts.cpython-310.pyc
ADDED
|
Binary file (1.27 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_basestring.cpython-310.pyc
ADDED
|
Binary file (915 Bytes). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_buffer.cpython-310.pyc
ADDED
|
Binary file (1.06 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_dict.cpython-310.pyc
ADDED
|
Binary file (3.28 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_except.cpython-310.pyc
ADDED
|
Binary file (3.03 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_execfile.cpython-310.pyc
ADDED
|
Binary file (1.67 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_filter.cpython-310.pyc
ADDED
|
Binary file (2.69 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_funcattrs.cpython-310.pyc
ADDED
|
Binary file (1.23 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_future.cpython-310.pyc
ADDED
|
Binary file (1.04 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_getcwdu.cpython-310.pyc
ADDED
|
Binary file (781 Bytes). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_idioms.cpython-310.pyc
ADDED
|
Binary file (3.9 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_import.cpython-310.pyc
ADDED
|
Binary file (3.07 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_imports2.cpython-310.pyc
ADDED
|
Binary file (539 Bytes). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_input.cpython-310.pyc
ADDED
|
Binary file (1.2 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_intern.cpython-310.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_isinstance.cpython-310.pyc
ADDED
|
Binary file (1.55 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_itertools.cpython-310.pyc
ADDED
|
Binary file (1.8 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_itertools_imports.cpython-310.pyc
ADDED
|
Binary file (1.56 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_long.cpython-310.pyc
ADDED
|
Binary file (963 Bytes). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_map.cpython-310.pyc
ADDED
|
Binary file (3.07 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_metaclass.cpython-310.pyc
ADDED
|
Binary file (5.4 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_methodattrs.cpython-310.pyc
ADDED
|
Binary file (1.19 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_ne.cpython-310.pyc
ADDED
|
Binary file (804 Bytes). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_next.cpython-310.pyc
ADDED
|
Binary file (3.33 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_numliterals.cpython-310.pyc
ADDED
|
Binary file (1.28 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_operator.cpython-310.pyc
ADDED
|
Binary file (4.41 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_paren.cpython-310.pyc
ADDED
|
Binary file (1.64 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_print.cpython-310.pyc
ADDED
|
Binary file (2.56 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_raise.cpython-310.pyc
ADDED
|
Binary file (2.24 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_raw_input.cpython-310.pyc
ADDED
|
Binary file (1.05 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_reduce.cpython-310.pyc
ADDED
|
Binary file (1.12 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_renames.cpython-310.pyc
ADDED
|
Binary file (2.28 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_repr.cpython-310.pyc
ADDED
|
Binary file (1.1 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_set_literal.cpython-310.pyc
ADDED
|
Binary file (1.94 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_sys_exc.cpython-310.pyc
ADDED
|
Binary file (1.67 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_throw.cpython-310.pyc
ADDED
|
Binary file (1.8 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_tuple_params.cpython-310.pyc
ADDED
|
Binary file (4.58 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_types.cpython-310.pyc
ADDED
|
Binary file (2.2 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_unicode.cpython-310.pyc
ADDED
|
Binary file (1.81 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_urllib.cpython-310.pyc
ADDED
|
Binary file (6.13 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_ws_comma.cpython-310.pyc
ADDED
|
Binary file (1.11 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_xrange.cpython-310.pyc
ADDED
|
Binary file (2.78 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_xreadlines.cpython-310.pyc
ADDED
|
Binary file (1.12 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/__pycache__/fix_zip.cpython-310.pyc
ADDED
|
Binary file (1.57 kB). View file
|
|
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/fix_apply.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2006 Google, Inc. All Rights Reserved.
|
| 2 |
+
# Licensed to PSF under a Contributor Agreement.
|
| 3 |
+
|
| 4 |
+
"""Fixer for apply().
|
| 5 |
+
|
| 6 |
+
This converts apply(func, v, k) into (func)(*v, **k)."""
|
| 7 |
+
|
| 8 |
+
# Local imports
|
| 9 |
+
from .. import pytree
|
| 10 |
+
from ..pgen2 import token
|
| 11 |
+
from .. import fixer_base
|
| 12 |
+
from ..fixer_util import Call, Comma, parenthesize
|
| 13 |
+
|
| 14 |
+
class FixApply(fixer_base.BaseFix):
|
| 15 |
+
BM_compatible = True
|
| 16 |
+
|
| 17 |
+
PATTERN = """
|
| 18 |
+
power< 'apply'
|
| 19 |
+
trailer<
|
| 20 |
+
'('
|
| 21 |
+
arglist<
|
| 22 |
+
(not argument<NAME '=' any>) func=any ','
|
| 23 |
+
(not argument<NAME '=' any>) args=any [','
|
| 24 |
+
(not argument<NAME '=' any>) kwds=any] [',']
|
| 25 |
+
>
|
| 26 |
+
')'
|
| 27 |
+
>
|
| 28 |
+
>
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
def transform(self, node, results):
|
| 32 |
+
syms = self.syms
|
| 33 |
+
assert results
|
| 34 |
+
func = results["func"]
|
| 35 |
+
args = results["args"]
|
| 36 |
+
kwds = results.get("kwds")
|
| 37 |
+
# I feel like we should be able to express this logic in the
|
| 38 |
+
# PATTERN above but I don't know how to do it so...
|
| 39 |
+
if args:
|
| 40 |
+
if (args.type == self.syms.argument and
|
| 41 |
+
args.children[0].value in {'**', '*'}):
|
| 42 |
+
return # Make no change.
|
| 43 |
+
if kwds and (kwds.type == self.syms.argument and
|
| 44 |
+
kwds.children[0].value == '**'):
|
| 45 |
+
return # Make no change.
|
| 46 |
+
prefix = node.prefix
|
| 47 |
+
func = func.clone()
|
| 48 |
+
if (func.type not in (token.NAME, syms.atom) and
|
| 49 |
+
(func.type != syms.power or
|
| 50 |
+
func.children[-2].type == token.DOUBLESTAR)):
|
| 51 |
+
# Need to parenthesize
|
| 52 |
+
func = parenthesize(func)
|
| 53 |
+
func.prefix = ""
|
| 54 |
+
args = args.clone()
|
| 55 |
+
args.prefix = ""
|
| 56 |
+
if kwds is not None:
|
| 57 |
+
kwds = kwds.clone()
|
| 58 |
+
kwds.prefix = ""
|
| 59 |
+
l_newargs = [pytree.Leaf(token.STAR, "*"), args]
|
| 60 |
+
if kwds is not None:
|
| 61 |
+
l_newargs.extend([Comma(),
|
| 62 |
+
pytree.Leaf(token.DOUBLESTAR, "**"),
|
| 63 |
+
kwds])
|
| 64 |
+
l_newargs[-2].prefix = " " # that's the ** token
|
| 65 |
+
# XXX Sometimes we could be cleverer, e.g. apply(f, (x, y) + t)
|
| 66 |
+
# can be translated into f(x, y, *t) instead of f(*(x, y) + t)
|
| 67 |
+
#new = pytree.Node(syms.power, (func, ArgList(l_newargs)))
|
| 68 |
+
return Call(func, l_newargs, prefix=prefix)
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/fix_asserts.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fixer that replaces deprecated unittest method names."""
|
| 2 |
+
|
| 3 |
+
# Author: Ezio Melotti
|
| 4 |
+
|
| 5 |
+
from ..fixer_base import BaseFix
|
| 6 |
+
from ..fixer_util import Name
|
| 7 |
+
|
| 8 |
+
NAMES = dict(
|
| 9 |
+
assert_="assertTrue",
|
| 10 |
+
assertEquals="assertEqual",
|
| 11 |
+
assertNotEquals="assertNotEqual",
|
| 12 |
+
assertAlmostEquals="assertAlmostEqual",
|
| 13 |
+
assertNotAlmostEquals="assertNotAlmostEqual",
|
| 14 |
+
assertRegexpMatches="assertRegex",
|
| 15 |
+
assertRaisesRegexp="assertRaisesRegex",
|
| 16 |
+
failUnlessEqual="assertEqual",
|
| 17 |
+
failIfEqual="assertNotEqual",
|
| 18 |
+
failUnlessAlmostEqual="assertAlmostEqual",
|
| 19 |
+
failIfAlmostEqual="assertNotAlmostEqual",
|
| 20 |
+
failUnless="assertTrue",
|
| 21 |
+
failUnlessRaises="assertRaises",
|
| 22 |
+
failIf="assertFalse",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class FixAsserts(BaseFix):
|
| 27 |
+
|
| 28 |
+
PATTERN = """
|
| 29 |
+
power< any+ trailer< '.' meth=(%s)> any* >
|
| 30 |
+
""" % '|'.join(map(repr, NAMES))
|
| 31 |
+
|
| 32 |
+
def transform(self, node, results):
|
| 33 |
+
name = results["meth"][0]
|
| 34 |
+
name.replace(Name(NAMES[str(name)], prefix=name.prefix))
|
evalkit_cambrian/lib/python3.10/lib2to3/fixes/fix_except.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fixer for except statements with named exceptions.
|
| 2 |
+
|
| 3 |
+
The following cases will be converted:
|
| 4 |
+
|
| 5 |
+
- "except E, T:" where T is a name:
|
| 6 |
+
|
| 7 |
+
except E as T:
|
| 8 |
+
|
| 9 |
+
- "except E, T:" where T is not a name, tuple or list:
|
| 10 |
+
|
| 11 |
+
except E as t:
|
| 12 |
+
T = t
|
| 13 |
+
|
| 14 |
+
This is done because the target of an "except" clause must be a
|
| 15 |
+
name.
|
| 16 |
+
|
| 17 |
+
- "except E, T:" where T is a tuple or list literal:
|
| 18 |
+
|
| 19 |
+
except E as t:
|
| 20 |
+
T = t.args
|
| 21 |
+
"""
|
| 22 |
+
# Author: Collin Winter
|
| 23 |
+
|
| 24 |
+
# Local imports
|
| 25 |
+
from .. import pytree
|
| 26 |
+
from ..pgen2 import token
|
| 27 |
+
from .. import fixer_base
|
| 28 |
+
from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, syms
|
| 29 |
+
|
| 30 |
+
def find_excepts(nodes):
|
| 31 |
+
for i, n in enumerate(nodes):
|
| 32 |
+
if n.type == syms.except_clause:
|
| 33 |
+
if n.children[0].value == 'except':
|
| 34 |
+
yield (n, nodes[i+2])
|
| 35 |
+
|
| 36 |
+
class FixExcept(fixer_base.BaseFix):
|
| 37 |
+
BM_compatible = True
|
| 38 |
+
|
| 39 |
+
PATTERN = """
|
| 40 |
+
try_stmt< 'try' ':' (simple_stmt | suite)
|
| 41 |
+
cleanup=(except_clause ':' (simple_stmt | suite))+
|
| 42 |
+
tail=(['except' ':' (simple_stmt | suite)]
|
| 43 |
+
['else' ':' (simple_stmt | suite)]
|
| 44 |
+
['finally' ':' (simple_stmt | suite)]) >
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
def transform(self, node, results):
|
| 48 |
+
syms = self.syms
|
| 49 |
+
|
| 50 |
+
tail = [n.clone() for n in results["tail"]]
|
| 51 |
+
|
| 52 |
+
try_cleanup = [ch.clone() for ch in results["cleanup"]]
|
| 53 |
+
for except_clause, e_suite in find_excepts(try_cleanup):
|
| 54 |
+
if len(except_clause.children) == 4:
|
| 55 |
+
(E, comma, N) = except_clause.children[1:4]
|
| 56 |
+
comma.replace(Name("as", prefix=" "))
|
| 57 |
+
|
| 58 |
+
if N.type != token.NAME:
|
| 59 |
+
# Generate a new N for the except clause
|
| 60 |
+
new_N = Name(self.new_name(), prefix=" ")
|
| 61 |
+
target = N.clone()
|
| 62 |
+
target.prefix = ""
|
| 63 |
+
N.replace(new_N)
|
| 64 |
+
new_N = new_N.clone()
|
| 65 |
+
|
| 66 |
+
# Insert "old_N = new_N" as the first statement in
|
| 67 |
+
# the except body. This loop skips leading whitespace
|
| 68 |
+
# and indents
|
| 69 |
+
#TODO(cwinter) suite-cleanup
|
| 70 |
+
suite_stmts = e_suite.children
|
| 71 |
+
for i, stmt in enumerate(suite_stmts):
|
| 72 |
+
if isinstance(stmt, pytree.Node):
|
| 73 |
+
break
|
| 74 |
+
|
| 75 |
+
# The assignment is different if old_N is a tuple or list
|
| 76 |
+
# In that case, the assignment is old_N = new_N.args
|
| 77 |
+
if is_tuple(N) or is_list(N):
|
| 78 |
+
assign = Assign(target, Attr(new_N, Name('args')))
|
| 79 |
+
else:
|
| 80 |
+
assign = Assign(target, new_N)
|
| 81 |
+
|
| 82 |
+
#TODO(cwinter) stopgap until children becomes a smart list
|
| 83 |
+
for child in reversed(suite_stmts[:i]):
|
| 84 |
+
e_suite.insert_child(0, child)
|
| 85 |
+
e_suite.insert_child(i, assign)
|
| 86 |
+
elif N.prefix == "":
|
| 87 |
+
# No space after a comma is legal; no space after "as",
|
| 88 |
+
# not so much.
|
| 89 |
+
N.prefix = " "
|
| 90 |
+
|
| 91 |
+
#TODO(cwinter) fix this when children becomes a smart list
|
| 92 |
+
children = [c.clone() for c in node.children[:3]] + try_cleanup + tail
|
| 93 |
+
return pytree.Node(node.type, children)
|