mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 20:24:30 +08:00
Use class with __call__ method instead of callable. (#2418)
This will enable checking positional and keyword parameters.
This commit is contained in:
committed by
Jelle Zijlstra
parent
5ed39dd8ce
commit
01abd34327
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from typing import Any, BinaryIO, Callable, Generator, IO, Iterable, List, Optional, Text, TextIO, Tuple, Type, TypeVar, Union
|
||||
from typing import Any, BinaryIO, Callable, Generator, IO, Iterable, List, Optional, Protocol, Text, TextIO, Tuple, Type, TypeVar, Union
|
||||
|
||||
from abc import abstractmethod
|
||||
import types
|
||||
@@ -13,14 +13,17 @@ import types
|
||||
_Decoded = Text
|
||||
_Encoded = bytes
|
||||
|
||||
# TODO: It is not possible to specify these signatures correctly, because
|
||||
# they have an optional positional or keyword argument for errors=.
|
||||
_Encoder = Callable[[_Decoded], Tuple[_Encoded, int]] # signature of Codec().encode
|
||||
_Decoder = Callable[[_Encoded], Tuple[_Decoded, int]] # signature of Codec().decode
|
||||
class _Encoder(Protocol):
|
||||
def __call__(self, input: _Decoded, errors: str = ...) -> Tuple[_Encoded, int]: ... # signature of Codec().encode
|
||||
class _Decoder(Protocol):
|
||||
def __call__(self, input: _Encoded, errors: str = ...) -> Tuple[_Decoded, int]: ... # signature of Codec().decode
|
||||
|
||||
# TODO: Replace the following Callable definitions with protocol classes as above.
|
||||
_StreamReader = Callable[[IO[_Encoded]], StreamReader] # signature of StreamReader __init__
|
||||
_StreamWriter = Callable[[IO[_Encoded]], StreamWriter] # signature of StreamWriter __init__
|
||||
_IncrementalEncoder = Callable[[], IncrementalEncoder] # signature of IncrementalEncoder __init__
|
||||
_IncrementalDecoder = Callable[[], IncrementalDecoder] # signature of IncrementalDecoder __init__
|
||||
|
||||
def encode(obj: _Decoded, encoding: str = ..., errors: str = ...) -> _Encoded: ...
|
||||
def decode(obj: _Encoded, encoding: str = ..., errors: str = ...) -> _Decoded: ...
|
||||
def lookup(encoding: str) -> CodecInfo: ...
|
||||
|
||||
Reference in New Issue
Block a user