From 65d1ba8b2e9b627b36e6720c9b934d2352bb3607 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 17 May 2024 21:28:57 -0400 Subject: [PATCH] Use 'next' to find a rule. --- cssutils/util.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cssutils/util.py b/cssutils/util.py index c21ec90c..ed48cfcc 100644 --- a/cssutils/util.py +++ b/cssutils/util.py @@ -817,12 +817,11 @@ def __setitem__(self, prefix, namespaceURI): def __findrule(self, prefix): # returns namespace rule where prefix == key - for rule in filter( - lambda r: r.type == r.NAMESPACE_RULE, + found = filter( + lambda r: r.type == r.NAMESPACE_RULE and r.prefix == prefix, reversed(self.parentStyleSheet.cssRules), - ): - if rule.prefix == prefix: - return rule + ) + return next(found, None) @property def namespaces(self):