Skip to content

Commit 0ca23b1

Browse files
committed
Second attempt at stricter typing.
1 parent 8d71839 commit 0ca23b1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

bpython/formatter.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# mypy: disallow_untyped_calls=True
2929

3030

31-
from typing import MutableMapping, Iterable, TextIO, Optional
31+
from typing import MutableMapping, Iterable, TextIO
3232
from pygments.formatter import Formatter
3333
from pygments.token import (
3434
_TokenType,
@@ -120,14 +120,15 @@ def format(
120120
) -> None:
121121
o: str = ""
122122
for token, text in tokensource:
123-
t: Optional[_TokenType] = token
124123
if text == "\n":
125124
continue
126125

127-
while t not in self.f_strings:
128-
if t is not None:
129-
t = t.parent
130-
o += f"{self.f_strings[t]}\x03{text}\x04"
126+
while token not in self.f_strings:
127+
if token.parent is None:
128+
break
129+
else:
130+
token = token.parent
131+
o += f"{self.f_strings[token]}\x03{text}\x04"
131132
outfile.write(o.rstrip())
132133

133134

0 commit comments

Comments
 (0)