Skip to content

Commit

Permalink
Merge pull request #125 from PyCQA/fix_append_call_break_help
Browse files Browse the repository at this point in the history
Fix append call breaks help
  • Loading branch information
ibizaman committed Dec 20, 2016
2 parents ded6209 + bf754af commit 782ada1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

0.6.3 (unreleased)
-----------------

- fix help() after append

0.6.2 (2016-10-03)
----------------

Expand Down
43 changes: 23 additions & 20 deletions redbaron/base_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ def _get_list_attribute_is_member_off(self):
if self.on_attribute is "root":
in_list = self.parent
elif self.on_attribute is not None:
in_list = getattr(self.parent, self.on_attribute)
if isinstance(self.parent, NodeList):
in_list = getattr(self.parent.parent, self.on_attribute)
else:
in_list = getattr(self.parent, self.on_attribute)
else:
return None

Expand Down Expand Up @@ -865,35 +868,35 @@ def generate_identifiers(klass):
def _get_helpers(self):
not_helpers = set([
'copy',
'decrease_indentation',
'dumps',
'edit',
'find',
'findAll',
'find_all',
'fst',
'help',
'next_generator',
'previous_generator',
'get_indentation_node',
'indentation_node_is_direct',
'parent_find',
'path',
'findAll',
'find_by_path',
'replace',
'edit',
'increase_indentation',
'decrease_indentation',
'has_render_key',
'get_absolute_bounding_box_of_attribute',
'find_by_position',
'parse_code_block',
'parse_decorators',
'from_fst',
'fst',
'generate_identifiers',
'get_absolute_bounding_box_of_attribute',
'get_indentation_node',
'has_render_key',
'help',
'increase_indentation',
'indentation_node_is_direct',
'index_on_parent',
'index_on_parent_raw',
'insert_before',
'insert_after',
'insert_before',
'next_generator',
'parent_find',
'parse_code_block',
'parse_decorators',
'path',
'previous_generator',
'replace',
'to_python',
'generate_identifiers',
])
return [x for x in dir(self) if
not x.startswith("_") and x not in not_helpers and inspect.ismethod(getattr(self, x))]
Expand Down
40 changes: 39 additions & 1 deletion tests/test_initial_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,49 @@ def test_get_helpers():
assert red[0]._get_helpers() == ['modules', 'names']


def test_help_is_not_crashing():
def test_help_is_not_crashing1():
some_code = "ax + (z * 4)"
red = RedBaron(some_code)
red.help()
red[0].help()
red.help(5)
red[0].help(5)
red.help(True)
red[0].help(True)


def test_help_is_not_crashing2():
some_code = "a(b)"
red = RedBaron(some_code)
red.help()
red[0].help()
red.help(5)
red[0].help(5)
red.help(True)
red[0].help(True)


def test_help_is_not_crashing3():
some_code = "a(b, c)"
red = RedBaron(some_code)
red.help()
red[0].help()
red.help(5)
red[0].help(5)
red.help(True)
red[0].help(True)


def test_help_is_not_crashing4():
some_code = "a(b)"
red = RedBaron(some_code)
red[0].call.append("c")
red.help()
red[0].help()
red.help(5)
red[0].help(5)
red.help(True)
red[0].help(True)


def test_assign_on_string_value():
Expand Down

0 comments on commit 782ada1

Please sign in to comment.