Walter Dörwald schrieb:
If a PEP is called for, I'd be happy to at least co-author it. Codecs are a major exception to Guido's law: Never have a parameter whose value switches between completely unrelated algorithms.
I don't think that applies here. This is more like __import__(): depending on the first parameter, completely different things can happen. Yes, the same import algorithm is used, but in the case of bytes.encode_bytes, the same algorithm is used to find and execute the codec.
What would a registry of tranformation algorithms buy us compared to a module with transformation functions?
Easier registering of custom transformations. Without a registry, you'd have to monkey-patch a module.
The function version is shorter:
transform.rot13('foo')
compared to:
'foo'.transform('rot13')
Yes, that's a very convincing argument :)
If each transformation has its own function, these functions can have their own arguments, e.g. transform.bz2encode(data: bytes, level: int=6) -> bytes
Of course str.transform() could pass along all arguments to the registered function, but that's worse from a documentation viewpoint, because the real signature is hidden deep in the registry.
I don't think transformation functions need arguments. Georg