Skip to content

Commit 4b26903

Browse files
committed
simplify trait interface
1 parent 076bd77 commit 4b26903

1 file changed

Lines changed: 11 additions & 38 deletions

File tree

Lib/test/support/hashlib_helper.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -752,45 +752,18 @@ def _find_constructor(self, digestname):
752752
self.is_valid_digest_name(digestname)
753753
self.skipTest(f"missing hash function: {digestname}")
754754

755-
@property
756-
def md5(self):
757-
return self._find_constructor("md5")
755+
md5 = property(lambda self: self._find_constructor("md5"))
756+
sha1 = property(lambda self: self._find_constructor("sha1"))
758757

759-
@property
760-
def sha1(self):
761-
return self._find_constructor("sha1")
758+
sha224 = property(lambda self: self._find_constructor("sha224"))
759+
sha256 = property(lambda self: self._find_constructor("sha256"))
760+
sha384 = property(lambda self: self._find_constructor("sha384"))
761+
sha512 = property(lambda self: self._find_constructor("sha512"))
762762

763-
@property
764-
def sha224(self):
765-
return self._find_constructor("sha224")
766-
767-
@property
768-
def sha256(self):
769-
return self._find_constructor("sha256")
770-
771-
@property
772-
def sha384(self):
773-
return self._find_constructor("sha384")
774-
775-
@property
776-
def sha512(self):
777-
return self._find_constructor("sha512")
778-
779-
@property
780-
def sha3_224(self):
781-
return self._find_constructor("sha3_224")
782-
783-
@property
784-
def sha3_256(self):
785-
return self._find_constructor("sha3_256")
786-
787-
@property
788-
def sha3_384(self):
789-
return self._find_constructor("sha3_384")
790-
791-
@property
792-
def sha3_512(self):
793-
return self._find_constructor("sha3_512")
763+
sha3_224 = property(lambda self: self._find_constructor("sha3_224"))
764+
sha3_256 = property(lambda self: self._find_constructor("sha3_256"))
765+
sha3_384 = property(lambda self: self._find_constructor("sha3_384"))
766+
sha3_512 = property(lambda self: self._find_constructor("sha3_512"))
794767

795768

796769
class NamedHashFunctionsTrait(HashFunctionsTrait):
@@ -801,7 +774,7 @@ class NamedHashFunctionsTrait(HashFunctionsTrait):
801774

802775
def _find_constructor(self, digestname):
803776
self.is_valid_digest_name(digestname)
804-
return digestname
777+
return str(digestname) # ensure that we are an exact string
805778

806779

807780
class OpenSSLHashFunctionsTrait(HashFunctionsTrait):

0 commit comments

Comments
 (0)