Skip to content

Commit fb2c7b3

Browse files
JelleZijlstramatthiaskramm
authored andcommitted
Improve itsdangerous stubs (#1733)
1 parent bb8b9bd commit fb2c7b3

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

third_party/2/itsdangerous.pyi

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PY2 = ... # type: bool
66
text_type = unicode
77
int_to_byte = chr
88
number_types = (int, long, float)
9+
_serializer = Any # must be an object that has "dumps" and "loads" attributes (e.g. the json module)
910

1011
bytes_like = Union[bytearray, str]
1112

@@ -16,7 +17,7 @@ class _CompactJSON:
1617
compact_json = _CompactJSON
1718
EPOCH = ... # type: int
1819

19-
def want_bytes(s: str, encoding='', errors='') -> str: ...
20+
def want_bytes(s: str, encoding: str = ..., errors: str = ...) -> bytes: ...
2021
def is_text_serializer(serializer: Any) -> bool: ...
2122
def constant_time_compare(val1: bytes_like, val2: bytes_like) -> bool: ...
2223

@@ -43,13 +44,13 @@ class BadHeader(BadSignature):
4344

4445
class SignatureExpired(BadTimeSignature): ...
4546

46-
def base64_encode(string: bytes_like) -> str: ...
47-
def base64_decode(string: bytes_like) -> str: ...
48-
def int_to_bytes(num: int) -> str: ...
49-
def bytes_to_int(bytestr: bytes_like) -> int: ...
47+
def base64_encode(string: bytes_like) -> bytes: ...
48+
def base64_decode(string: bytes_like) -> bytes: ...
49+
def int_to_bytes(num: int) -> bytes: ...
50+
def bytes_to_int(bytestr: bytes_like) -> bytes: ...
5051

5152
class SigningAlgorithm:
52-
def get_signature(self, key: bytes_like, value: bytes_like) -> str: ...
53+
def get_signature(self, key: bytes_like, value: bytes_like) -> bytes: ...
5354
def verify_signature(self, key: bytes_like, value: bytes_like, sig: bytes_like) -> bool: ...
5455

5556
class NoneAlgorithm(SigningAlgorithm):
@@ -59,7 +60,7 @@ class HMACAlgorithm(SigningAlgorithm):
5960
default_digest_method = ... # type: Callable
6061
digest_method = ... # type: Callable
6162
def __init__(self, digest_method: Optional[Callable] = ...) -> None: ...
62-
def get_signature(self, key: bytes_like, value: bytes_like) -> str: ...
63+
def get_signature(self, key: bytes_like, value: bytes_like) -> bytes: ...
6364

6465
class Signer:
6566
default_digest_method = ... # type: Callable
@@ -70,35 +71,35 @@ class Signer:
7071
key_derivation = ... # type: str
7172
digest_method = ... # type: Callable
7273
algorithm = ... # type: SigningAlgorithm
73-
def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like] = ..., sep: Optional[str]='',
74+
def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like] = ..., sep: Optional[str] = ...,
7475
key_derivation: Optional[str] = ...,
7576
digest_method: Optional[Callable] = ...,
7677
algorithm: Optional[SigningAlgorithm] = ...) -> None: ...
77-
def derive_key(self) -> str: ...
78-
def get_signature(self, value: bytes_like) -> str: ...
79-
def sign(self, value: bytes_like) -> str: ...
78+
def derive_key(self) -> bytes: ...
79+
def get_signature(self, value: bytes_like) -> bytes: ...
80+
def sign(self, value: bytes_like) -> bytes: ...
8081
def verify_signature(self, value: bytes_like, sig: bytes_like) -> bool: ...
8182
def unsign(self, signed_value: str) -> str: ...
8283
def validate(self, signed_value: str) -> bool: ...
8384

8485
class TimestampSigner(Signer):
8586
def get_timestamp(self) -> int: ...
8687
def timestamp_to_datetime(self, ts: int) -> datetime: ...
87-
def sign(self, value: bytes_like) -> str: ...
88-
def unsign(self, value: str, max_age: Optional[int] = ..., return_timestamp=False) -> Any: ...
88+
def sign(self, value: bytes_like) -> bytes: ...
89+
def unsign(self, value: str, max_age: Optional[int] = ..., return_timestamp: bool = ...) -> Any: ...
8990
def validate(self, signed_value: str, max_age: Optional[int] = ...) -> bool: ...
9091

9192
class Serializer:
92-
default_serializer = ... # type: Any
93+
default_serializer = ... # type: _serializer
9394
default_signer = ... # type: Callable[..., Signer]
9495
secret_key = ... # type: Any
9596
salt = ... # type: bytes_like
96-
serializer = ... # type: Any
97+
serializer = ... # type: _serializer
9798
is_text_serializer = ... # type: bool
9899
signer = ... # type: Signer
99100
signer_kwargs = ... # type: MutableMapping
100-
def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like]=b'', serializer=None, signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ...) -> None: ...
101-
def load_payload(self, payload: Any, serializer=None) -> Any: ...
101+
def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ...) -> None: ...
102+
def load_payload(self, payload: Any, serializer: Optional[_serializer] = ...) -> Any: ...
102103
def dump_payload(self, *args, **kwargs) -> str: ...
103104
def make_signer(self, salt: Optional[bytes_like] = ...) -> Signer: ...
104105
def dumps(self, obj: Any, salt: Optional[bytes_like] = ...) -> str: ...
@@ -110,7 +111,7 @@ class Serializer:
110111

111112
class TimedSerializer(Serializer):
112113
default_signer = ... # type: Callable[..., TimestampSigner]
113-
def loads(self, s: str, salt: Optional[bytes_like] = ..., max_age: Optional[int] = ..., return_timestamp=False) -> Any: ...
114+
def loads(self, s: str, salt: Optional[bytes_like] = ..., max_age: Optional[int] = ..., return_timestamp: bool = ...) -> Any: ...
114115
def loads_unsafe(self, s: str, salt: Optional[bytes_like] = ..., max_age: Optional[int] = ...) -> Tuple[bool, Any]: ...
115116

116117
class JSONWebSignatureSerializer(Serializer):
@@ -119,22 +120,22 @@ class JSONWebSignatureSerializer(Serializer):
119120
default_serializer = ... # type: Any
120121
algorithm_name = ... # type: str
121122
algorithm = ... # type: Any
122-
def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like] = ..., serializer=None, signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ..., algorithm_name: Optional[str] = ...) -> None: ...
123-
def load_payload(self, payload: Any, return_header=False) -> Any: ...
124-
def dump_payload(self, *args, **kwargs) -> str: ...
123+
def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ..., algorithm_name: Optional[str] = ...) -> None: ...
124+
def load_payload(self, payload: Any, serializer: Optional[_serializer] = ..., return_header: bool = ...) -> Any: ...
125+
def dump_payload(self, *args, **kwargs) -> bytes: ...
125126
def make_algorithm(self, algorithm_name: str) -> SigningAlgorithm: ...
126127
def make_signer(self, salt: Optional[bytes_like] = ..., algorithm_name: Optional[str] = ...) -> Signer: ...
127-
def make_header(self, header_fields=Optional[MutableMapping]) -> MutableMapping: ...
128-
def dumps(self, obj: Any, salt: Optional[bytes_like] = ..., header_fields=Optional[MutableMapping]) -> str: ...
129-
def loads(self, s: str, salt: Optional[bytes_like] = ..., return_header=False) -> Any: ...
130-
def loads_unsafe(self, s, salt: Optional[bytes_like] = ..., return_header=False) -> Tuple[bool, Any]: ...
128+
def make_header(self, header_fields: Optional[MutableMapping] = ...) -> MutableMapping: ...
129+
def dumps(self, obj: Any, salt: Optional[bytes_like] = ..., header_fields: Optional[MutableMapping] = ...) -> str: ...
130+
def loads(self, s: str, salt: Optional[bytes_like] = ..., return_header: bool = ...) -> Any: ...
131+
def loads_unsafe(self, s, salt: Optional[bytes_like] = ..., return_header: bool = ...) -> Tuple[bool, Any]: ...
131132

132133
class TimedJSONWebSignatureSerializer(JSONWebSignatureSerializer):
133134
DEFAULT_EXPIRES_IN = ... # type: int
134135
expires_in = ... # type: int
135136
def __init__(self, secret_key: bytes_like, expires_in: Optional[int] = ..., **kwargs) -> None: ...
136137
def make_header(self, header_fields=Optional[MutableMapping]) -> MutableMapping: ...
137-
def loads(self, s: str, salt: Optional[bytes_like] = ..., return_header=False) -> Any: ...
138+
def loads(self, s: str, salt: Optional[bytes_like] = ..., return_header: bool = ...) -> Any: ...
138139
def get_issue_date(self, header: MutableMapping) -> Optional[datetime]: ...
139140
def now(self) -> int: ...
140141

third_party/3/itsdangerous.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class _CompactJSON:
2020
compact_json = _CompactJSON
2121
EPOCH = ... # type: int
2222

23-
def want_bytes(s: _can_become_bytes, encoding: str='', errors: str='') -> bytes: ...
23+
def want_bytes(s: _can_become_bytes, encoding: str = ..., errors: str = ...) -> bytes: ...
2424
def is_text_serializer(serializer: _serializer) -> bool: ...
2525
def constant_time_compare(val1: _comparable_bytes, val2: _comparable_bytes) -> bool: ...
2626

@@ -74,7 +74,7 @@ class Signer:
7474
key_derivation = ... # type: str
7575
digest_method = ... # type: Callable
7676
algorithm = ... # type: SigningAlgorithm
77-
def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., sep: Optional[_can_become_bytes]='',
77+
def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., sep: Optional[_can_become_bytes] = ...,
7878
key_derivation: Optional[str] = ...,
7979
digest_method: Optional[Callable] = ...,
8080
algorithm: Optional[SigningAlgorithm] = ...) -> None: ...
@@ -101,8 +101,8 @@ class Serializer:
101101
is_text_serializer = ... # type: bool
102102
signer = ... # type: Signer
103103
signer_kwargs = ... # type: MutableMapping
104-
def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes]=b'', serializer: _serializer=None, signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ...) -> None: ...
105-
def load_payload(self, payload: Any, serializer: _serializer=None) -> Any: ...
104+
def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ...) -> None: ...
105+
def load_payload(self, payload: Any, serializer: Optional[_serializer] = ...) -> Any: ...
106106
def dump_payload(self, *args, **kwargs) -> bytes: ...
107107
def make_signer(self, salt: Optional[_can_become_bytes] = ...) -> Signer: ...
108108
def dumps(self, obj: Any, salt: Optional[_can_become_bytes] = ...) -> _str_like: ...
@@ -123,8 +123,8 @@ class JSONWebSignatureSerializer(Serializer):
123123
default_serializer = ... # type: Any
124124
algorithm_name = ... # type: str
125125
algorithm = ... # type: Any
126-
def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., serializer: _serializer=None, signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ..., algorithm_name: Optional[str] = ...) -> None: ...
127-
def load_payload(self, payload: Any, serializer: _serializer = None, return_header: bool = ...) -> Any: ...
126+
def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ..., algorithm_name: Optional[str] = ...) -> None: ...
127+
def load_payload(self, payload: Any, serializer: Optional[_serializer] = ..., return_header: bool = ...) -> Any: ...
128128
def dump_payload(self, *args, **kwargs) -> bytes: ...
129129
def make_algorithm(self, algorithm_name: str) -> SigningAlgorithm: ...
130130
def make_signer(self, salt: Optional[_can_become_bytes] = ..., algorithm_name: Optional[str] = ...) -> Signer: ...

0 commit comments

Comments
 (0)