Skip to content

Commit e574f0d

Browse files
authored
fix: Remove unnecessary string casting of bytes (#276)
1 parent f5cf6b9 commit e574f0d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/hpack/hpack.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,16 @@ def _dict_to_iterable(header_dict):
143143
yield key, header_dict[key]
144144

145145

146-
def _to_bytes(string):
146+
def _to_bytes(value):
147147
"""
148-
Convert string to bytes.
148+
Convert anything to bytes through a UTF-8 encoded string
149149
"""
150-
if not isinstance(string, basestring): # pragma: no cover
151-
string = str(string)
152-
153-
return string if isinstance(string, bytes) else string.encode('utf-8')
150+
t = type(value)
151+
if t is bytes:
152+
return value
153+
if t is not str:
154+
value = str(value)
155+
return value.encode("utf-8")
154156

155157

156158
class Encoder:

0 commit comments

Comments
 (0)