Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3a70dc

Browse files
authored
typing of inputsplitter (#14219)
2 parents d55e23e + 93a7083 commit e3a70dc

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

IPython/core/inputsplitter.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import tokenize
3232
import warnings
3333

34-
from typing import List
34+
from typing import List, Tuple, Union
3535

3636
from IPython.core.inputtransformer import (leading_indent,
3737
classic_prompt,
@@ -150,7 +150,7 @@ def partial_tokens(s):
150150
else:
151151
raise
152152

153-
def find_next_indent(code):
153+
def find_next_indent(code) -> int:
154154
"""Find the number of spaces for the next line of indentation"""
155155
tokens = list(partial_tokens(code))
156156
if tokens[-1].type == tokenize.ENDMARKER:
@@ -324,15 +324,15 @@ class InputSplitter(object):
324324
# If self.source matches the first value, the second value is a valid
325325
# current indentation. Otherwise, the cache is invalid and the indentation
326326
# must be recalculated.
327-
_indent_spaces_cache = None, None
327+
_indent_spaces_cache: Union[Tuple[None, None], Tuple[str, int]] = None, None
328328
# String, indicating the default input encoding. It is computed by default
329329
# at initialization time via get_input_encoding(), but it can be reset by a
330330
# client with specific knowledge of the encoding.
331331
encoding = ''
332332
# String where the current full source input is stored, properly encoded.
333333
# Reading this attribute is the normal way of querying the currently pushed
334334
# source code, that has been properly encoded.
335-
source = ''
335+
source: str = ""
336336
# Code object corresponding to the current source. It is automatically
337337
# synced to the source, so it can be queried at any time to obtain the code
338338
# object; it will be None if the source doesn't compile to valid Python.
@@ -517,9 +517,10 @@ def push_accepts_more(self):
517517
# General fallback - accept more code
518518
return True
519519

520-
def get_indent_spaces(self):
520+
def get_indent_spaces(self) -> int:
521521
sourcefor, n = self._indent_spaces_cache
522522
if sourcefor == self.source:
523+
assert n is not None
523524
return n
524525

525526
# self.source always has a trailing newline
@@ -568,7 +569,7 @@ class IPythonInputSplitter(InputSplitter):
568569
# Private attributes
569570

570571
# List with lines of raw input accumulated so far.
571-
_buffer_raw = None
572+
_buffer_raw: List[str]
572573

573574
def __init__(self, line_input_checker=True, physical_line_transforms=None,
574575
logical_line_transforms=None, python_line_transforms=None):
@@ -658,8 +659,8 @@ def _flush(transform, outs):
658659
tmp = transform.reset()
659660
if tmp is not None:
660661
yield tmp
661-
662-
out = []
662+
663+
out: List[str] = []
663664
for t in self.transforms_in_use:
664665
out = _flush(t, out)
665666

0 commit comments

Comments
 (0)