Skip to content

Commit 492e3d5

Browse files
rcred7sebastinas
authored andcommitted
Added type annotations
Sebastian: fixed some type annotations
1 parent dc667b6 commit 492e3d5

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

bpython/curtsiesfrontend/interpreter.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import sys
2-
from typing import Any, Dict, Optional
2+
from codeop import CommandCompiler
3+
from typing import Any, Dict, Iterable, Optional, Tuple, Union
34

45
from pygments.token import Generic, Token, Keyword, Name, Comment, String
56
from pygments.token import Error, Literal, Number, Operator, Punctuation
6-
from pygments.token import Whitespace
7+
from pygments.token import Whitespace, _TokenType
78
from pygments.formatter import Formatter
89
from pygments.lexers import get_lexer_by_name
10+
from curtsies.formatstring import FmtStr
911

1012
from ..curtsiesfrontend.parse import parse
1113
from ..repl import Interpreter as ReplInterpreter
@@ -43,7 +45,11 @@ class BPythonFormatter(Formatter):
4345
See the Pygments source for more info; it's pretty
4446
straightforward."""
4547

46-
def __init__(self, color_scheme, **options):
48+
def __init__(
49+
self,
50+
color_scheme: Dict[_TokenType, str],
51+
**options: Union[str, bool, None],
52+
) -> None:
4753
self.f_strings = {k: f"\x01{v}" for k, v in color_scheme.items()}
4854
super().__init__(**options)
4955

@@ -71,7 +77,7 @@ def __init__(
7177

7278
# typically changed after being instantiated
7379
# but used when interpreter used corresponding REPL
74-
def write(err_line):
80+
def write(err_line: Union[str, FmtStr]) -> None:
7581
"""Default stderr handler for tracebacks
7682
7783
Accepts FmtStrs so interpreters can output them"""
@@ -80,13 +86,14 @@ def write(err_line):
8086
self.write = write # type: ignore
8187
self.outfile = self
8288

83-
def writetb(self, lines):
89+
def writetb(self, lines: Iterable[str]) -> None:
8490
tbtext = "".join(lines)
8591
lexer = get_lexer_by_name("pytb")
8692
self.format(tbtext, lexer)
8793
# TODO for tracebacks get_lexer_by_name("pytb", stripall=True)
8894

89-
def format(self, tbtext, lexer):
95+
def format(self, tbtext: str, lexer: Any) -> None:
96+
# FIXME: lexer should is a Lexer
9097
traceback_informative_formatter = BPythonFormatter(default_colors)
9198
traceback_code_formatter = BPythonFormatter({Token: ("d")})
9299
tokens = list(lexer.get_tokens(tbtext))
@@ -112,7 +119,9 @@ def format(self, tbtext, lexer):
112119
assert cur_line == [], cur_line
113120

114121

115-
def code_finished_will_parse(s, compiler):
122+
def code_finished_will_parse(
123+
s: str, compiler: CommandCompiler
124+
) -> Tuple[bool, bool]:
116125
"""Returns a tuple of whether the buffer could be complete and whether it
117126
will parse
118127

0 commit comments

Comments
 (0)