From: Štěpán Balážik Date: Wed, 28 Jan 2026 14:21:58 +0000 (+0100) Subject: Fix 'Too many return statements' pylint error X-Git-Tag: v9.21.19~15^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19076c0d4d39410c7060094faebccc0803312606;p=thirdparty%2Fbind9.git Fix 'Too many return statements' pylint error Refactor `Key.match_properties` into multiple functions. --- diff --git a/bin/tests/system/isctest/kasp.py b/bin/tests/system/isctest/kasp.py index 96d874fa296..9364f3c752d 100644 --- a/bin/tests/system/isctest/kasp.py +++ b/bin/tests/system/isctest/kasp.py @@ -650,14 +650,10 @@ class Key: isctest.log.debug(f"{self.name} {key} TIMING UNEXPECTED: {value}") return value == "undefined" - def match_properties(self, zone, properties): + def _check_public_key_file(self, zone, properties): """ - Check the key with given properties. + Check the public key file. """ - # Check file existence. - # Noop. If file is missing then the get_metadata calls will fail. - - # Check the public key file. role = properties.role_full() comment = f"This is a {role} key, keyid {self.tag}, for {zone}." if not isctest.util.file_contents_contain(self.keyfile, comment): @@ -672,31 +668,45 @@ class Key: isctest.log.debug(f"{self.name} DNSKEY MISMATCH: expected '{dnskey}'") return False - # Now check the private key file. - if properties.private: - # Retrieve creation date. - created = self.get_metadata("Generated") + return True - pval = self.get_metadata("Created", file=self.privatefile) - if pval != created: - isctest.log.debug( - f"{self.name} Created METADATA MISMATCH: {pval} - {created}" - ) - return False - pval = self.get_metadata("Private-key-format", file=self.privatefile) - if pval != "v1.3": - isctest.log.debug( - f"{self.name} Private-key-format METADATA MISMATCH: {pval} - v1.3" - ) - return False - pval = self.get_metadata("Algorithm", file=self.privatefile) - if pval != f"{alg}": - isctest.log.debug( - f"{self.name} Algorithm METADATA MISMATCH: {pval} - {alg}" - ) - return False + def _check_private_key_file(self, properties): + """ + Check the private key file. + """ + if not properties.private: + return True + + alg = properties.metadata["Algorithm"] + + # Retrieve creation date. + created = self.get_metadata("Generated") + + pval = self.get_metadata("Created", file=self.privatefile) + if pval != created: + isctest.log.debug( + f"{self.name} Created METADATA MISMATCH: {pval} - {created}" + ) + return False + pval = self.get_metadata("Private-key-format", file=self.privatefile) + if pval != "v1.3": + isctest.log.debug( + f"{self.name} Private-key-format METADATA MISMATCH: {pval} - v1.3" + ) + return False + pval = self.get_metadata("Algorithm", file=self.privatefile) + if pval != f"{alg}": + isctest.log.debug( + f"{self.name} Algorithm METADATA MISMATCH: {pval} - {alg}" + ) + return False - # Now check the key state file. + return True + + def _check_key_state_file(self, zone, properties): + """ + Check the key state file. + """ if properties.legacy: return True @@ -727,7 +737,24 @@ class Key: if self.tag > properties.keytag_max: return False - # A match is found. + return True + + def match_properties(self, zone, properties): + """ + Check the key with given properties. + """ + # Check file existence. + # Noop. If file is missing then the get_metadata calls will fail. + + if not self._check_public_key_file(zone, properties): + return False + + if not self._check_private_key_file(properties): + return False + + if not self._check_key_state_file(zone, properties): + return False + return True def match_timingmetadata(self, timings, file=None, comment=False): diff --git a/pyproject.toml b/pyproject.toml index 9b6d430ec91..4aed089859e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,6 @@ disable = [ "R0801", # duplicate-code "R0902", # too-many-instance-attributes "R0903", # too-few-public-methods - "R0911", # too-many-return-statements "R0912", # too-many-branches "R0913", # too-many-arguments "R0914", # too-many-locals