{"action":"opened","issue":{"url":"https://api.github.com/repos/PyCQA/redbaron/issues/176","repository_url":"https://api.github.com/repos/PyCQA/redbaron","labels_url":"https://api.github.com/repos/PyCQA/redbaron/issues/176/labels{/name}","comments_url":"https://api.github.com/repos/PyCQA/redbaron/issues/176/comments","events_url":"https://api.github.com/repos/PyCQA/redbaron/issues/176/events","html_url":"https://github.com/PyCQA/redbaron/issues/176","id":385988176,"node_id":"MDU6SXNzdWUzODU5ODgxNzY=","number":176,"title":"Inserting node causes `.help()` to crash","user":{"login":"jrs65","id":695206,"node_id":"MDQ6VXNlcjY5NTIwNg==","avatar_url":"https://avatars2.githubusercontent.com/u/695206?v=4","gravatar_id":"","url":"https://api.github.com/users/jrs65","html_url":"https://github.com/jrs65","followers_url":"https://api.github.com/users/jrs65/followers","following_url":"https://api.github.com/users/jrs65/following{/other_user}","gists_url":"https://api.github.com/users/jrs65/gists{/gist_id}","starred_url":"https://api.github.com/users/jrs65/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrs65/subscriptions","organizations_url":"https://api.github.com/users/jrs65/orgs","repos_url":"https://api.github.com/users/jrs65/repos","events_url":"https://api.github.com/users/jrs65/events{/privacy}","received_events_url":"https://api.github.com/users/jrs65/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-11-30T00:38:24Z","updated_at":"2018-11-30T00:38:24Z","closed_at":null,"author_association":"NONE","body":"I'm trying to use Red Baron (which seems great), but I'm having a bit of a weird crash when inserting nodes. This actually fails with the example given in the documentation\r\n```python\r\nred = RedBaron(\"foo = 42\\nprint('bar')\\n\")\r\nred.help()  # Works fine as expected\r\nred.print_.insert_before(\"baz\")\r\nred.help()  # Crashes with output below.\r\n```\r\nHowever, other then `.help()` everything seems to work fine after the insertion. For instance:\r\n```python\r\n>>> print red.dumps()\r\nfoo = 42\r\nbaz\r\nprint('bar')\r\n```\r\n\r\nI'm using:\r\n```bash\r\n$ pip list | grep baron\r\nbaron                              0.8\r\nredbaron                           0.8\r\n```\r\non Python 2.7.15.\r\n\r\nThe full output and traceback of the `.help()` call is:\r\n```\r\n0 -----------------------------------------------------\r\nAssignmentNode()\r\n  # identifiers: assign, assignment, assignment_, assignmentnode\r\n  operator=''\r\n  target ->\r\n    NameNode()\r\n      # identifiers: name, name_, namenode\r\n      value=u'foo'\r\n  value ->\r\n    IntNode()\r\n      # identifiers: int, int_, intnode\r\n      value=u'42'\r\n1 -----------------------------------------------------\r\nEndlNode()\r\n  # identifiers: endl, endl_, endlnode\r\n  value=u'\\n'\r\n  indent=''\r\n2 -----------------------------------------------------\r\nNameNode()\r\n  # identifiers: name, name_, namenode\r\n  value=u'baz'\r\n3 -----------------------------------------------------\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.py\", line 36, in wrapper\r\n    return function(*args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.py\", line 293, in root\r\n    current = current.parent\r\nAttributeError: 'NoneType' object has no attribute 'parent'\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.py\", line 36, in wrapper\r\n    return function(*args, **kwargs)\r\n  File \"/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.py\", line 227, in absolute_bounding_box\r\n    return baron.path.path_to_bounding_box(self.root.fst(), path)\r\n  File \"/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.py\", line 718, in __getattr__\r\n    self.__class__.__name__, key, key))\r\nAttributeError: EndlNode instance has no attribute 'root' and 'root' is not a valid identifier of another node\r\n---------------------------------------------------------------------------\r\nAttributeError                            Traceback (most recent call last)\r\n<ipython-input-12-857370972330> in <module>()\r\n----> 1 red.help()\r\n\r\n/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.pyc in help(self, deep, with_formatting)\r\n    420         for num, i in enumerate(self.data):\r\n    421             sys.stdout.write(str(num) + \" -----------------------------------------------------\\n\")\r\n--> 422             i.help(deep=deep, with_formatting=with_formatting)\r\n    423 \r\n    424     def __help__(self, deep=2, with_formatting=False):\r\n\r\n/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.pyc in help(self, deep, with_formatting)\r\n    953     def help(self, deep=2, with_formatting=False):\r\n    954         if runned_from_ipython():\r\n--> 955             sys.stdout.write(help_highlight(self.__help__(deep=deep, with_formatting=with_formatting) + \"\\n\"))\r\n    956         else:\r\n    957             sys.stdout.write(self.__help__(deep=deep, with_formatting=with_formatting) + \"\\n\")\r\n\r\n/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.pyc in __help__(self, deep, with_formatting)\r\n    966         else:\r\n    967             to_join.append(\"# identifiers: %s\" % \", \".join(self.generate_identifiers()))\r\n--> 968             if self._get_helpers():\r\n    969                 to_join.append(\"# helpers: %s\" % \", \".join(self._get_helpers()))\r\n    970             if self._default_test_value != \"value\":\r\n\r\n/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.pyc in _get_helpers(self)\r\n    929         ])\r\n    930         return [x for x in dir(self) if\r\n--> 931                 not x.startswith(\"_\") and x not in not_helpers and inspect.ismethod(getattr(self, x))]\r\n    932 \r\n    933     def fst(self):\r\n\r\n/usr/local/lib/python2.7/site-packages/redbaron/base_nodes.pyc in __getattr__(self, key)\r\n    716             raise AttributeError(\r\n    717                 \"%s instance has no attribute '%s' and '%s' is not a valid identifier of another node\" % (\r\n--> 718                     self.__class__.__name__, key, key))\r\n    719 \r\n    720         return self.find(key)\r\n\r\nAttributeError: EndlNode instance has no attribute 'absolute_bounding_box' and 'absolute_bounding_box' is not a valid identifier of another node\r\n```"}}
{"actor":{"display_login":"jrs65"}}