@@ -4043,14 +4043,27 @@ class buffer: pass
40434043class rwbuffer : pass
40444044class robuffer : pass
40454045
4046- StrConverterKeyType = tuple [frozenset [type [object ]], bool , bool ]
4046+ @dc .dataclass
4047+ class StrConverterKey :
4048+ accept : frozenset [type [object ]]
4049+ encoding : bool
4050+ zeroes : bool
4051+
4052+ def __hash__ (self ) -> int :
4053+ return hash ((self .accept , self .encoding , self .zeroes ))
4054+
4055+ def __str__ (self ) -> str :
4056+ accept = "{" + ", " .join ([tp .__name__ for tp in self .accept ]) + "}"
4057+ encoding = 'encodingname' if self .encoding else None
4058+ zeroes = self .zeroes
4059+ return f"{ accept = !r} , { encoding = !r} , { zeroes = !r} "
40474060
40484061def str_converter_key (
40494062 types : TypeSet , encoding : bool | str | None , zeroes : bool
4050- ) -> StrConverterKeyType :
4051- return (frozenset (types ), bool (encoding ), bool (zeroes ))
4063+ ) -> StrConverterKey :
4064+ return StrConverterKey (frozenset (types ), bool (encoding ), bool (zeroes ))
40524065
4053- str_converter_argument_map : dict [StrConverterKeyType , str ] = {}
4066+ str_converter_argument_map : dict [StrConverterKey , str ] = {}
40544067
40554068class str_converter (CConverter ):
40564069 type = 'const char *'
@@ -4068,7 +4081,10 @@ def converter_init(
40684081 key = str_converter_key (accept , encoding , zeroes )
40694082 format_unit = str_converter_argument_map .get (key )
40704083 if not format_unit :
4071- fail ("str_converter: illegal combination of arguments" , key )
4084+ fail ("unsupported combination of str converter arguments: "
4085+ f"{ accept = !r} , { encoding = !r} , { zeroes = !r} ; "
4086+ "allowed combinations are:\n \n "
4087+ f"{ '\n ' .join ([str (k ) for k in str_converter_argument_map .keys ()])} " )
40724088
40734089 self .format_unit = format_unit
40744090 self .length = bool (zeroes )
0 commit comments