Commit f2ca7218 authored by Stefan Behnel's avatar Stefan Behnel

no need to use yield for now

parent d737fed4
...@@ -63,7 +63,7 @@ def embed_position(pos, docstring): ...@@ -63,7 +63,7 @@ def embed_position(pos, docstring):
doc.encoding = encoding doc.encoding = encoding
return doc return doc
class AttributeAccessor: class _AttributeAccessor(object):
"""Used as the result of the Node.get_children_accessors() generator""" """Used as the result of the Node.get_children_accessors() generator"""
def __init__(self, obj, attrname): def __init__(self, obj, attrname):
self.obj = obj self.obj = obj
...@@ -78,7 +78,18 @@ class AttributeAccessor: ...@@ -78,7 +78,18 @@ class AttributeAccessor:
def name(self): def name(self):
return self.attrname return self.attrname
class Node: class _AttributeIterator(object):
"""Used as the result of the Node.get_children_accessors() generator"""
def __init__(self, obj, attrnames):
self.obj = obj
self.attrnames = iter(attrnames)
def __iter__(self):
return self
def __next__(self):
return _AttributeAccessor(self.obj, self.attrnames.next())
next = __next__
class Node(object):
# pos (string, int, int) Source file position # pos (string, int, int) Source file position
# is_name boolean Is a NameNode # is_name boolean Is a NameNode
# is_literal boolean Is a ConstNode # is_literal boolean Is a ConstNode
...@@ -129,13 +140,7 @@ class Node: ...@@ -129,13 +140,7 @@ class Node:
if attrnames is None: if attrnames is None:
raise InternalError("Children access not implemented for %s" % \ raise InternalError("Children access not implemented for %s" % \
self.__class__.__name__) self.__class__.__name__)
for name in attrnames: return _AttributeIterator(self, attrnames)
a = AttributeAccessor(self, name)
yield a
# Not really needed, but one wants to enforce clients not to
# hold on to iterated objects, in case more advanced iteration
# is needed later
a.attrname = None
def get_child_attrs(self): def get_child_attrs(self):
"""Utility method for more easily implementing get_child_accessors. """Utility method for more easily implementing get_child_accessors.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment