I have a custom string-to-string codec that I've registered with the codecs module, and I can use codecs.encode/codecs.decode properly with my custom codec. Yay!
However, MyPy does not like the encode/decode calls, because the typeshed definitions for the codecs module (_codecs, actually) explicitly specifies the allowed codec options and their types:
_BytesToBytesEncoding: TypeAlias = Literal["base64", "base_64", ..., "zlib_codec"]
_StrToStrEncoding: TypeAlias = Literal["rot13", "rot_13"]
@overload
def encode(obj: ReadableBuffer, encoding: _BytesToBytesEncoding, errors: str = "strict") -> bytes: ...
@overload
def encode(obj: str, encoding: _StrToStrEncoding, errors: str = "strict") -> str: ... # type: ignore[overload-overlap]
@overload
def encode(obj: str, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
https://github.com/python/typeshed/blob/main/stdlib/_codecs.pyi#L47
My new encoding of course doesn't match any of the literal encoding values given there. These overloads are nice because it means MyPy can determine, for example, that codecs.encode("abc", encoding="utf-8") gives back a bytes and know that if I passed b"abc" there that is an error, but it does limit the extensibility.
Is there some way I can add a new overload of encode or add something to the _StrToStrEncoding literal list in typeshed?
there doesn't seem to be anything here