Skip to content

Commit d8fd11b

Browse files
committed
add typing information
1 parent 6d6b66c commit d8fd11b

37 files changed

+477
-440
lines changed

src/h2/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
h2
43
~~

src/h2/config.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
h2/config
43
~~~~~~~~~
@@ -7,21 +6,22 @@
76
"""
87

98
import sys
9+
from typing import Any, Optional, Union
1010

1111

1212
class _BooleanConfigOption:
1313
"""
1414
Descriptor for handling a boolean config option. This will block
1515
attempts to set boolean config options to non-bools.
1616
"""
17-
def __init__(self, name):
17+
def __init__(self, name: str) -> None:
1818
self.name = name
1919
self.attr_name = '_%s' % self.name
2020

21-
def __get__(self, instance, owner):
22-
return getattr(instance, self.attr_name)
21+
def __get__(self, instance: Any, owner: Any) -> bool:
22+
return getattr(instance, self.attr_name) # type: ignore
2323

24-
def __set__(self, instance, value):
24+
def __set__(self, instance: Any, value: bool) -> None:
2525
if not isinstance(value, bool):
2626
raise ValueError("%s must be a bool" % self.name)
2727
setattr(instance, self.attr_name, value)
@@ -35,16 +35,16 @@ class DummyLogger:
3535
conditionals being sprinkled throughout the h2 code for calls to
3636
logging functions when no logger is passed into the corresponding object.
3737
"""
38-
def __init__(self, *vargs):
38+
def __init__(self, *vargs) -> None: # type: ignore
3939
pass
4040

41-
def debug(self, *vargs, **kwargs):
41+
def debug(self, *vargs, **kwargs) -> None: # type: ignore
4242
"""
4343
No-op logging. Only level needed for now.
4444
"""
4545
pass
4646

47-
def trace(self, *vargs, **kwargs):
47+
def trace(self, *vargs, **kwargs) -> None: # type: ignore
4848
"""
4949
No-op logging. Only level needed for now.
5050
"""
@@ -61,15 +61,15 @@ class OutputLogger:
6161
Defaults to ``sys.stderr``.
6262
:param trace: Enables trace-level output. Defaults to ``False``.
6363
"""
64-
def __init__(self, file=None, trace_level=False):
64+
def __init__(self, file=None, trace_level=False): # type: ignore
6565
super().__init__()
6666
self.file = file or sys.stderr
6767
self.trace_level = trace_level
6868

69-
def debug(self, fmtstr, *args):
69+
def debug(self, fmtstr, *args): # type: ignore
7070
print(f"h2 (debug): {fmtstr % args}", file=self.file)
7171

72-
def trace(self, fmtstr, *args):
72+
def trace(self, fmtstr, *args): # type: ignore
7373
if self.trace_level:
7474
print(f"h2 (trace): {fmtstr % args}", file=self.file)
7575

@@ -165,14 +165,14 @@ class H2Configuration:
165165
)
166166

167167
def __init__(self,
168-
client_side=True,
169-
header_encoding=None,
170-
validate_outbound_headers=True,
171-
normalize_outbound_headers=True,
172-
split_outbound_cookies=False,
173-
validate_inbound_headers=True,
174-
normalize_inbound_headers=True,
175-
logger=None):
168+
client_side: bool = True,
169+
header_encoding: Optional[Union[bool, str]] = None,
170+
validate_outbound_headers: bool = True,
171+
normalize_outbound_headers: bool = True,
172+
split_outbound_cookies: bool = False,
173+
validate_inbound_headers: bool = True,
174+
normalize_inbound_headers: bool = True,
175+
logger: Optional[Union[DummyLogger, OutputLogger]] = None) -> None:
176176
self.client_side = client_side
177177
self.header_encoding = header_encoding
178178
self.validate_outbound_headers = validate_outbound_headers
@@ -183,7 +183,7 @@ def __init__(self,
183183
self.logger = logger or DummyLogger(__name__)
184184

185185
@property
186-
def header_encoding(self):
186+
def header_encoding(self) -> Optional[Union[bool, str]]:
187187
"""
188188
Controls whether the headers emitted by this object in events are
189189
transparently decoded to ``unicode`` strings, and what encoding is used
@@ -195,7 +195,7 @@ def header_encoding(self):
195195
return self._header_encoding
196196

197197
@header_encoding.setter
198-
def header_encoding(self, value):
198+
def header_encoding(self, value: Optional[Union[bool, str]]) -> None:
199199
"""
200200
Enforces constraints on the value of header encoding.
201201
"""

0 commit comments

Comments
 (0)