From 09c1d212574d9c84dce1905f5943b5da7e637d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aneta=20Pokorn=C3=A1?= Date: Tue, 16 Feb 2021 20:53:37 +0100 Subject: [PATCH] =?UTF-8?q?Dops=C3=A1na=20a=20trochu=20otestov=C3=A1na=20f?= =?UTF-8?q?unkce=20get=5Fupper=5Fnode=5Fof=5Ftype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/treelib.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/seminar/treelib.py b/seminar/treelib.py index 9482079a..1835bf1c 100644 --- a/seminar/treelib.py +++ b/seminar/treelib.py @@ -217,6 +217,17 @@ def get_prev_node_of_type(node, type): return current return None +def get_upper_node_of_type(node, type): + # vrací první vyšší node daného typu (ignoruje sourozence) + if node is None: + return + current = node + while get_parent(current) is not None: + current = get_parent(current) + if isinstance(current, type): + return current + return None + # Exception, kterou některé metody při špatném použití mohou házet