Skip to content

Commit 944fba8

Browse files
committed
chore: multiple changes for ruff: imports, spacing, == -> is
sort imports use is to compare types not == turn foo[n-1] into foo[n - 1] allow some loop vars to change value in loop (PLW2901)
1 parent aa57c9c commit 944fba8

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

roundup/anypy/email_.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import re
21
import binascii
32
import email
4-
from email import quoprimime, base64mime
3+
import re
4+
from email import base64mime, quoprimime
55
from email import charset as _charset
66

7-
if str == bytes:
7+
if str is bytes:
88
message_from_bytes = email.message_from_string
99
message_from_binary_file = email.message_from_file
1010
else:
@@ -74,8 +74,8 @@ def decode_header(header):
7474
# between two encoded strings.
7575
droplist = []
7676
for n, w in enumerate(words):
77-
if n > 1 and w[1] and words[n-2][1] and words[n-1][0].isspace():
78-
droplist.append(n-1)
77+
if n > 1 and w[1] and words[n - 2][1] and words[n - 1][0].isspace():
78+
droplist.append(n - 1)
7979
for d in reversed(droplist):
8080
del words[d]
8181

@@ -94,7 +94,7 @@ def decode_header(header):
9494
# Postel's law: add missing padding
9595
paderr = len(encoded_string) % 4
9696
if paderr:
97-
encoded_string += '==='[:4 - paderr]
97+
encoded_string += '==='[:4 - paderr] # noqa: PLW2901
9898
try:
9999
word = base64mime.decode(encoded_string)
100100
except binascii.Error:
@@ -108,8 +108,9 @@ def decode_header(header):
108108
collapsed = []
109109
last_word = last_charset = None
110110
for word, charset in decoded_words:
111-
if isinstance(word, str) and bytes != str:
112-
word = bytes(word, 'raw-unicode-escape')
111+
# ruff: noqa: PLW2901 - loop var word is overwritten
112+
if isinstance(word, str) and bytes is not str:
113+
word = bytes(word, 'raw-unicode-escape') # PLW2901
113114
if last_word is None:
114115
last_word = word
115116
last_charset = charset

0 commit comments

Comments
 (0)