Skip to content

Commit

Permalink
[enh] add yield from node
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycojoker committed Aug 9, 2018
1 parent f9d4d6e commit 0d622ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions redbaron/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,15 @@ def _string_to_node(self, string, parent, on_attribute):
raise Exception("Unhandled case")


class YieldFromNode(Node):
def _string_to_node(self, string, parent, on_attribute):
if on_attribute == "value":
return Node.from_fst(baron.parse("yield from %s" % string)[0]["value"], parent=parent, on_attribute=on_attribute)

else:
raise Exception("Unhandled case")


class YieldAtomNode(Node):
def _string_to_node(self, string, parent, on_attribute):
if on_attribute == "value":
Expand Down
8 changes: 8 additions & 0 deletions tests/test_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,14 @@ def test_yield_atom_setattr_value_was_none():
assert red.dumps() == "(yield a)"


def test_yield_from_setattr_value():
red = RedBaron("yield from a")
red[0].value = "hop"
assert red.dumps() == "yield from hop"
with pytest.raises(Exception):
red[0].value = "def a(): pass\n"


def test_list_comprehension_set_attr_result():
red = RedBaron("[a for b in c]")
red[0].result = "hop"
Expand Down

0 comments on commit 0d622ab

Please sign in to comment.