Skip to content

Commit 8d71839

Browse files
committed
Added temp variable to allow for stricter typing.
1 parent 895fdc0 commit 8d71839

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎bpython/formatter.py‎

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

3030

31-
from typing import MutableMapping, Any, Iterable, TextIO
31+
from typing import MutableMapping, Iterable, TextIO, Optional
3232
from pygments.formatter import Formatter
3333
from pygments.token import (
34+
_TokenType,
3435
Keyword,
3536
Name,
3637
Comment,
@@ -113,16 +114,20 @@ def __init__(
113114
super().__init__(**options)
114115

115116
def format(
116-
self, tokensource: Iterable[MutableMapping[Any, str]], outfile: TextIO
117+
self,
118+
tokensource: Iterable[MutableMapping[_TokenType, str]],
119+
outfile: TextIO,
117120
) -> None:
118121
o: str = ""
119122
for token, text in tokensource:
123+
t: Optional[_TokenType] = token
120124
if text == "\n":
121125
continue
122126

123-
while token not in self.f_strings:
124-
token = token.parent
125-
o += f"{self.f_strings[token]}\x03{text}\x04"
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"
126131
outfile.write(o.rstrip())
127132

128133

0 commit comments

Comments
 (0)