From 93a4039a72e464e45f8266242fa2e6891c52efcd Mon Sep 17 00:00:00 2001 From: Lenny Truong Date: Thu, 24 Jul 2025 11:10:26 -0700 Subject: [PATCH] Fix match API to allow pattern or string --- pydevicetree/ast/node.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pydevicetree/ast/node.py b/pydevicetree/ast/node.py index 9d579e9..81ef4d2 100644 --- a/pydevicetree/ast/node.py +++ b/pydevicetree/ast/node.py @@ -247,12 +247,14 @@ def filter(self, matchFunc: MatchFunc, cbFunc: MatchCallback = None) -> List['No return nodes - def match(self, compatible: Pattern, func: MatchCallback = None) -> List['Node']: + def match(self, compatible: Pattern | str, func: MatchCallback = None) -> List['Node']: """Get a node from the subtree by compatible string Accepts a regular expression to match one of the strings in the compatible property. """ - regex = re.compile(compatible) + regex = compatible + if isinstance(regex, str): + regex = re.compile(regex) def match_compat(node: Node) -> bool: compatibles = node.get_fields("compatible")