How to check runtime bevahiour:
# main.py
import codecs
def decode(input: bytes, errors: str = 'strict') -> tuple[str, int]:
print(type(input))
return '', len(input)
def encode(input: str, errors: str = 'strict') -> tuple[bytes, int]:
raise NotImplementedError
def search(name: str) -> codecs.CodecInfo | None:
if name == 'test':
return codecs.CodecInfo(encode, decode)
return None
codecs.register(search)
import a
# a.py:
# coding: test
a = 1
When i run this code, decode prints <class 'memoryview'>, which is inconsistent with codecs._Decoder annotation.
Annotating input as memoryview doesnt help, because codecs.CodecInfo accepts only function that takes input arg of type bytes.