Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Restructuring a method call and parameter to an operator

Received: by 10.91.11.33 with SMTP id o33mr123477agi.16.1298474079672;
        Wed, 23 Feb 2011 07:14:39 -0800 (PST)
X-BeenThere: rope-dev@googlegroups.com
Received: by 10.91.87.7 with SMTP id p7ls171125agl.3.p; Wed, 23 Feb 2011
 07:14:39 -0800 (PST)
MIME-Version: 1.0
Received: by 10.91.169.18 with SMTP id w18mr23467ago.21.1298474079047; Wed, 23
 Feb 2011 07:14:39 -0800 (PST)
Received: by o21g2000prn.googlegroups.com with HTTP; Wed, 23 Feb 2011 07:14:38
 -0800 (PST)
Date: Wed, 23 Feb 2011 07:14:38 -0800 (PST)
In-Reply-To: <20112302174706@lilem.mirepesht>
X-IP: 146.232.65.6
References: <b8c4dcb9-6268-4f9d-9fd1-1672fe1249d6@z27g2000prz.googlegroups.com>
 <20112302174706@lilem.mirepesht>
User-Agent: G2/1.0
X-HTTP-Via: 1.1 proxy0.sun.ac.za:3128 (squid/2.7.STABLE3)
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13)
 Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13,gzip(gfe)
Message-ID: <8d4b3ff5-4591-4ac2-adc1-073667af2b33@o21g2000prn.googlegroups.com>
Subject: Re: Restructuring a method call and parameter to an operator
From: Neilen <nmar...@gmail.com>
To: rope-dev <rope-dev@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Ali

On Feb 23, 4:17=A0pm, Ali Gholami Rudi <aligr...@gmail.com> wrote:
> Hi,
>
> > Due to scipy depricating A.matvec(v) where A is a sparse matrix and v
> > a vector, I need to do the following transform:
>
> You may be the second person who actually used restructurings for
> something real (the first being me) ;-)

:)

>
> > with no success. Is there a way to do this? Do let me know if I need
> > to paste backtraces!
>
> Let's see if it works when done directly (assuming it is run in project
> root):
>
> =A0 from rope.base import project
> =A0 from rope.refactor import restructure
>
> =A0 p =3D project.Project('.')
> =A0 r =3D restructure.Restructure(p, '${p1}.matvec(${p2})', '${p1} * ${p2=
}')
> =A0 p.do(r.get_changes())
>
> Does it work?

I get the following error message and (rather long) bactrace:

ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (72, 0))

ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (26, 0))

ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (17, 0))

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call
last)

/home/nmarais/akademie/dev/femcode/main/NewCode/<ipython console> in
<module>()

/usr/lib/python2.6/dist-packages/rope/refactor/restructure.pyc in
get_changes(self, checks, imports, resources, task_handle)
    141             pymodule =3D
self.pycore.resource_to_pyobject(resource)
    142             finder =3D similarfinder.SimilarFinder(pymodule,
--> 143
wildcards=3Dself.wildcards)
    144             matches =3D list(finder.get_matches(self.pattern,
self.args))
    145             computer =3D self._compute_changes(matches,
pymodule)

/usr/lib/python2.6/dist-packages/rope/refactor/similarfinder.pyc in
__init__(self, pymodule, wildcards)
     24         self.source =3D pymodule.source_code
     25         self.raw_finder =3D RawSimilarFinder(
---> 26             pymodule.source_code, pymodule.get_ast(),
self._does_match)
     27         self.pymodule =3D pymodule
     28         if wildcards is None:

/usr/lib/python2.6/dist-packages/rope/refactor/similarfinder.pyc in
__init__(self, source, node, does_match)
     70         else:
     71             self.does_match =3D does_match
---> 72         self._init_using_ast(node, source)
     73
     74     def _simple_does_match(self, node, name):

/usr/lib/python2.6/dist-packages/rope/refactor/similarfinder.pyc in
_init_using_ast(self, node, source)
     79         self._matched_asts =3D {}
     80         if not hasattr(node, 'region'):
---> 81             patchedast.patch_ast(node, source)
     82         self.ast =3D node
     83

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
patch_ast(node, source, sorted_children)
     31         return node
     32     walker =3D _PatchingASTWalker(source,
children=3Dsorted_children)
---> 33     ast.call_for_nodes(node, walker)
     34     return node
     35

/usr/lib/python2.6/dist-packages/rope/base/ast.pyc in
call_for_nodes(node, callback, recursive)
     51 def call_for_nodes(node, callback, recursive=3DFalse):
     52     """If callback returns `True` the child nodes are
skipped"""
---> 53     result =3D callback(node)
     54     if recursive and not result:
     55         for child in get_child_nodes(node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
__call__(self, node)
     73         method =3D getattr(self, '_' + node.__class__.__name__,
None)
     74         if method is not None:
---> 75             return method(node)
     76         # ???: Unknown node; what should we do here?

     77         warnings.warn('Unknown node type <%s>; please report!'

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_Module(self, node)
    473
    474     def _Module(self, node):
--> 475         self._handle(node, list(node.body), eat_spaces=3DTrue)
    476
    477     def _Name(self, node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_handle(self, node, base_children, eat_parens, eat_spaces)
    101             offset =3D self.source.offset
    102             if isinstance(child, ast.AST):
--> 103                 ast.call_for_nodes(child, self)
    104                 token_start =3D child.region[0]
    105             else:

/usr/lib/python2.6/dist-packages/rope/base/ast.pyc in
call_for_nodes(node, callback, recursive)
     51 def call_for_nodes(node, callback, recursive=3DFalse):
     52     """If callback returns `True` the child nodes are
skipped"""
---> 53     result =3D callback(node)
     54     if recursive and not result:
     55         for child in get_child_nodes(node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
__call__(self, node)
     73         method =3D getattr(self, '_' + node.__class__.__name__,
None)
     74         if method is not None:
---> 75             return method(node)
     76         # ???: Unknown node; what should we do here?

     77         warnings.warn('Unknown node type <%s>; please report!'

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_ClassDef(self, node)
    283         children.append(':')
    284         children.extend(node.body)
--> 285         self._handle(node, children)
    286
    287     def _Compare(self, node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_handle(self, node, base_children, eat_parens, eat_spaces)
    101             offset =3D self.source.offset
    102             if isinstance(child, ast.AST):
--> 103                 ast.call_for_nodes(child, self)
    104                 token_start =3D child.region[0]
    105             else:

/usr/lib/python2.6/dist-packages/rope/base/ast.pyc in
call_for_nodes(node, callback, recursive)
     51 def call_for_nodes(node, callback, recursive=3DFalse):
     52     """If callback returns `True` the child nodes are
skipped"""
---> 53     result =3D callback(node)
     54     if recursive and not result:
     55         for child in get_child_nodes(node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
__call__(self, node)
     73         method =3D getattr(self, '_' + node.__class__.__name__,
None)
     74         if method is not None:
---> 75             return method(node)
     76         # ???: Unknown node; what should we do here?

     77         warnings.warn('Unknown node type <%s>; please report!'

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_FunctionDef(self, node)
    366         children.extend([')', ':'])
    367         children.extend(node.body)
--> 368         self._handle(node, children)
    369
    370     def _arguments(self, node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_handle(self, node, base_children, eat_parens, eat_spaces)
    101             offset =3D self.source.offset
    102             if isinstance(child, ast.AST):
--> 103                 ast.call_for_nodes(child, self)
    104                 token_start =3D child.region[0]
    105             else:

/usr/lib/python2.6/dist-packages/rope/base/ast.pyc in
call_for_nodes(node, callback, recursive)
     51 def call_for_nodes(node, callback, recursive=3DFalse):
     52     """If callback returns `True` the child nodes are
skipped"""
---> 53     result =3D callback(node)
     54     if recursive and not result:
     55         for child in get_child_nodes(node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
__call__(self, node)
     73         method =3D getattr(self, '_' + node.__class__.__name__,
None)
     74         if method is not None:
---> 75             return method(node)
     76         # ???: Unknown node; what should we do here?

     77         warnings.warn('Unknown node type <%s>; please report!'

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_If(self, node)
    437                 children.extend(['else', ':'])
    438             children.extend(node.orelse)
--> 439         self._handle(node, children)
    440
    441     def _is_elif(self, node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_handle(self, node, base_children, eat_parens, eat_spaces)
    101             offset =3D self.source.offset
    102             if isinstance(child, ast.AST):
--> 103                 ast.call_for_nodes(child, self)
    104                 token_start =3D child.region[0]
    105             else:

/usr/lib/python2.6/dist-packages/rope/base/ast.pyc in
call_for_nodes(node, callback, recursive)
     51 def call_for_nodes(node, callback, recursive=3DFalse):
     52     """If callback returns `True` the child nodes are
skipped"""
---> 53     result =3D callback(node)
     54     if recursive and not result:
     55         for child in get_child_nodes(node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
__call__(self, node)
     73         method =3D getattr(self, '_' + node.__class__.__name__,
None)
     74         if method is not None:
---> 75             return method(node)
     76         # ???: Unknown node; what should we do here?

     77         warnings.warn('Unknown node type <%s>; please report!'

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_Compare(self, node)
    291             children.extend(self._get_op(op))
    292             children.append(expr)
--> 293         self._handle(node, children)
    294
    295     def _Delete(self, node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_handle(self, node, base_children, eat_parens, eat_spaces)
    101             offset =3D self.source.offset
    102             if isinstance(child, ast.AST):
--> 103                 ast.call_for_nodes(child, self)
    104                 token_start =3D child.region[0]
    105             else:

/usr/lib/python2.6/dist-packages/rope/base/ast.pyc in
call_for_nodes(node, callback, recursive)
     51 def call_for_nodes(node, callback, recursive=3DFalse):
     52     """If callback returns `True` the child nodes are
skipped"""
---> 53     result =3D callback(node)
     54     if recursive and not result:
     55         for child in get_child_nodes(node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
__call__(self, node)
     73         method =3D getattr(self, '_' + node.__class__.__name__,
None)
     74         if method is not None:
---> 75             return method(node)
     76         # ???: Unknown node; what should we do here?

     77         warnings.warn('Unknown node type <%s>; please report!'

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_Subscript(self, node)
    523
    524     def _Subscript(self, node):
--> 525         self._handle(node, [node.value, '[', node.slice, ']'])
    526
    527     def _Slice(self, node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_handle(self, node, base_children, eat_parens, eat_spaces)
    101             offset =3D self.source.offset
    102             if isinstance(child, ast.AST):
--> 103                 ast.call_for_nodes(child, self)
    104                 token_start =3D child.region[0]
    105             else:

/usr/lib/python2.6/dist-packages/rope/base/ast.pyc in
call_for_nodes(node, callback, recursive)
     51 def call_for_nodes(node, callback, recursive=3DFalse):
     52     """If callback returns `True` the child nodes are
skipped"""
---> 53     result =3D callback(node)
     54     if recursive and not result:
     55         for child in get_child_nodes(node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
__call__(self, node)
     73         method =3D getattr(self, '_' + node.__class__.__name__,
None)
     74         if method is not None:
---> 75             return method(node)
     76         # ???: Unknown node; what should we do here?

     77         warnings.warn('Unknown node type <%s>; please report!'

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_Index(self, node)
    520
    521     def _Index(self, node):
--> 522         self._handle(node, [node.value])
    523
    524     def _Subscript(self, node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_handle(self, node, base_children, eat_parens, eat_spaces)
    101             offset =3D self.source.offset
    102             if isinstance(child, ast.AST):
--> 103                 ast.call_for_nodes(child, self)
    104                 token_start =3D child.region[0]
    105             else:

/usr/lib/python2.6/dist-packages/rope/base/ast.pyc in
call_for_nodes(node, callback, recursive)
     51 def call_for_nodes(node, callback, recursive=3DFalse):
     52     """If callback returns `True` the child nodes are
skipped"""
---> 53     result =3D callback(node)
     54     if recursive and not result:
     55         for child in get_child_nodes(node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
__call__(self, node)
     73         method =3D getattr(self, '_' + node.__class__.__name__,
None)
     74         if method is not None:
---> 75             return method(node)
     76         # ???: Unknown node; what should we do here?

     77         warnings.warn('Unknown node type <%s>; please report!'

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_Str(self, node)
    300
    301     def _Str(self, node):
--> 302         self._handle(node, [self.String])
    303
    304     def _Continue(self, node):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_handle(self, node, base_children, eat_parens, eat_spaces)
    106                 if child is self.String:
    107                     region =3D self.source.consume_string(
--> 108                         end=3Dself._find_next_statement_start())
    109                 elif child is self.Number:
    110                     region =3D self.source.consume_number()

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
consume_string(self, end)
    639             _Source._string_pattern =3D re.compile(pattern)
    640         repattern =3D _Source._string_pattern
--> 641         return self._consume_pattern(repattern, end)
    642
    643     def consume_number(self):

/usr/lib/python2.6/dist-packages/rope/refactor/patchedast.pyc in
_consume_pattern(self, repattern, end)
    680                 end =3D len(self.source)
    681             match =3D repattern.search(self.source, self.offset,
end)
--> 682             if self._good_token(match.group(), match.start()):
    683                 break
    684             else:

AttributeError: 'NoneType' object has no attribute 'group'



Best