Browse Source

baseconv: use match statement where practicable

The MMGen Project 2 months ago
parent
commit
e29c464ebb
1 changed files with 11 additions and 8 deletions
  1. 11 8
      mmgen/baseconv.py

+ 11 - 8
mmgen/baseconv.py

@@ -124,14 +124,17 @@ class baseconv:
 		def do_die():
 			die('BaseConversionPadError', f"{pad!r}: illegal value for 'pad' (must be None, 'seed' or int)")
 
-		if pad is None:
-			return 0
-		elif type(pad) is int:
-			return pad
-		elif pad == 'seed':
-			return seed_pad_func()
-		else:
-			do_die()
+		match pad:
+			case None:
+				return 0
+			case bool():
+				do_die()
+			case int():
+				return pad
+			case 'seed':
+				return seed_pad_func()
+			case _:
+				do_die()
 
 	def tohex(self, words_arg, /, *, pad=None):
 		"convert string or list data of instance base to a hexadecimal string"