Skip to content

Commit 2b2421a

Browse files
committed
fix: Remove unnecessary string casting of bytes
1 parent 02afcab commit 2b2421a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/hpack/hpack.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ def _to_bytes(string):
147147
"""
148148
Convert string to bytes.
149149
"""
150-
if not isinstance(string, basestring): # pragma: no cover
151-
string = str(string)
150+
if isinstance(string, bytes):
151+
return string
152152

153-
return string if isinstance(string, bytes) else string.encode('utf-8')
153+
# Not doing an `isinstance(string, basestring)` check here
154+
# as the cost of it is the same as just running `str()` on
155+
# an object that is already a string
156+
return str(string).encode("utf-8")
154157

155158

156159
class Encoder:

0 commit comments

Comments
 (0)