redbaron icon indicating copy to clipboard operation
redbaron copied to clipboard

handle indented cases in CommaProxyList

Open Psycojoker opened this issue 9 years ago • 2 comments

Quite a lot of work, we need to list/detect common situation where we could find an identation in a CommaList and see how we have to behave. Here is an example of a failing situation.

A "quick win" would be to have a default behavior (even a bad one) instead of an exception (which sucks).

In [7]: RedBaron("def __init__(self, a,\n   b, c): pass")[0].arguments.pop()
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-7-4d3f9b02d5b0> in <module>()
----> 1 RedBaron("def __init__(self, a,\n   b, c): pass")[0].arguments.pop()

/home/psycojoker/code/python/redbaron/redbaron/base_nodes.pyc in pop(self, index)
   1348         else:
   1349             self.data.pop()
-> 1350         self._synchronise()
   1351 
   1352     def remove(self, value):

/home/psycojoker/code/python/redbaron/redbaron/base_nodes.pyc in _synchronise(self)
   1325 
   1326     def _synchronise(self):
-> 1327         self.node_list.data = self._generate_expected_list()[:]
   1328         self.data = self._build_inner_list(self.node_list.data)
   1329 

/home/psycojoker/code/python/redbaron/redbaron/base_nodes.pyc in _generate_expected_list(self)
   1493                     if self.style == "indented":
   1494                         if not expected_list[-1].second_formatting.endl:
-> 1495                             raise Exception("Unhandled case")
   1496                         elif expected_list[-1].second_formatting.endl.indent != self.parent.indentation + " "*4:
   1497                             expected_list[-1].second_formatting.endl.indent = self.parent.indentation + " "*4

Exception: Unhandled case

Psycojoker avatar Apr 23 '16 02:04 Psycojoker

@Psycojoker Is there any chance you can merge the linked PR? That would considerably help parsing black formatted code.

Pugio avatar Jul 07 '20 12:07 Pugio

Found this and now I am thinking about switching from redbaron to libcst... No progress here yet?

vlkv avatar Jul 19 '23 11:07 vlkv