refactor node markers, remove need to be aware of nodes

This commit is contained in:
Ronny Pfannschmidt 2018-03-18 16:52:43 +01:00
parent 2d06ae0f65
commit 5e56e9b4f6
2 changed files with 7 additions and 11 deletions

View File

@ -369,13 +369,8 @@ class NodeKeywords(MappingMixin):
@attr.s(cmp=False, hash=False)
class NodeMarkers(object):
node = attr.ib(repr=False)
own_markers = attr.ib(default=attr.Factory(list))
@classmethod
def from_node(cls, node):
return cls(node=node)
def update(self, add_markers):
"""update the own markers
"""
@ -386,7 +381,6 @@ class NodeMarkers(object):
find markers in own nodes or parent nodes
needs a better place
"""
for node in reversed(self.node.listchain()):
for mark in node._markers.own_markers:
if mark.name == name:
yield mark
for mark in self.own_markers:
if mark.name == name:
yield mark

View File

@ -90,7 +90,7 @@ class Node(object):
#: keywords/markers collected from all scopes
self.keywords = NodeKeywords(self)
self._markers = NodeMarkers.from_node(self)
self._markers = NodeMarkers()
#: allow adding of extra keywords to use for matching
self.extra_keyword_matches = set()
@ -184,7 +184,9 @@ class Node(object):
def find_markers(self, name):
"""find all marks with the given name on the node and its parents"""
return self._markers.find(name)
for node in reversed(self.listchain()):
for mark in node._markers.find(name):
yield mark
def get_marker(self, name):
""" get a marker object from this node or None if