|
31 | 31 | import tokenize |
32 | 32 | import warnings |
33 | 33 |
|
34 | | -from typing import List |
| 34 | +from typing import List, Tuple, Union |
35 | 35 |
|
36 | 36 | from IPython.core.inputtransformer import (leading_indent, |
37 | 37 | classic_prompt, |
@@ -150,7 +150,7 @@ def partial_tokens(s): |
150 | 150 | else: |
151 | 151 | raise |
152 | 152 |
|
153 | | -def find_next_indent(code): |
| 153 | +def find_next_indent(code) -> int: |
154 | 154 | """Find the number of spaces for the next line of indentation""" |
155 | 155 | tokens = list(partial_tokens(code)) |
156 | 156 | if tokens[-1].type == tokenize.ENDMARKER: |
@@ -324,15 +324,15 @@ class InputSplitter(object): |
324 | 324 | # If self.source matches the first value, the second value is a valid |
325 | 325 | # current indentation. Otherwise, the cache is invalid and the indentation |
326 | 326 | # must be recalculated. |
327 | | - _indent_spaces_cache = None, None |
| 327 | + _indent_spaces_cache: Union[Tuple[None, None], Tuple[str, int]] = None, None |
328 | 328 | # String, indicating the default input encoding. It is computed by default |
329 | 329 | # at initialization time via get_input_encoding(), but it can be reset by a |
330 | 330 | # client with specific knowledge of the encoding. |
331 | 331 | encoding = '' |
332 | 332 | # String where the current full source input is stored, properly encoded. |
333 | 333 | # Reading this attribute is the normal way of querying the currently pushed |
334 | 334 | # source code, that has been properly encoded. |
335 | | - source = '' |
| 335 | + source: str = "" |
336 | 336 | # Code object corresponding to the current source. It is automatically |
337 | 337 | # synced to the source, so it can be queried at any time to obtain the code |
338 | 338 | # object; it will be None if the source doesn't compile to valid Python. |
@@ -517,9 +517,10 @@ def push_accepts_more(self): |
517 | 517 | # General fallback - accept more code |
518 | 518 | return True |
519 | 519 |
|
520 | | - def get_indent_spaces(self): |
| 520 | + def get_indent_spaces(self) -> int: |
521 | 521 | sourcefor, n = self._indent_spaces_cache |
522 | 522 | if sourcefor == self.source: |
| 523 | + assert n is not None |
523 | 524 | return n |
524 | 525 |
|
525 | 526 | # self.source always has a trailing newline |
@@ -568,7 +569,7 @@ class IPythonInputSplitter(InputSplitter): |
568 | 569 | # Private attributes |
569 | 570 |
|
570 | 571 | # List with lines of raw input accumulated so far. |
571 | | - _buffer_raw = None |
| 572 | + _buffer_raw: List[str] |
572 | 573 |
|
573 | 574 | def __init__(self, line_input_checker=True, physical_line_transforms=None, |
574 | 575 | logical_line_transforms=None, python_line_transforms=None): |
@@ -658,8 +659,8 @@ def _flush(transform, outs): |
658 | 659 | tmp = transform.reset() |
659 | 660 | if tmp is not None: |
660 | 661 | yield tmp |
661 | | - |
662 | | - out = [] |
| 662 | + |
| 663 | + out: List[str] = [] |
663 | 664 | for t in self.transforms_in_use: |
664 | 665 | out = _flush(t, out) |
665 | 666 |
|
|
0 commit comments