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

Skip to content

Commit c2dc68b

Browse files
committed
Reduce types in splitinput.py
As far as I can tell, those are always strings, so should remove some overhead.
1 parent ce9a3a4 commit c2dc68b

1 file changed

Lines changed: 17 additions & 22 deletions

File tree

IPython/core/splitinput.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
# encoding: utf-8
21
"""
32
Simple utility for splitting user input. This is used by both inputsplitter and
43
prefilter.
5-
6-
Authors:
7-
8-
* Brian Granger
9-
* Fernando Perez
104
"""
115

12-
#-----------------------------------------------------------------------------
13-
# Copyright (C) 2008-2011 The IPython Development Team
14-
#
15-
# Distributed under the terms of the BSD License. The full license is in
16-
# the file COPYING, distributed as part of this software.
17-
#-----------------------------------------------------------------------------
18-
196
#-----------------------------------------------------------------------------
207
# Imports
218
#-----------------------------------------------------------------------------
229

2310
import re
2411
import sys
2512

26-
from IPython.utils import py3compat
27-
from IPython.utils.encoding import get_stream_enc
2813
from IPython.core.oinspect import OInfo
2914

3015
#-----------------------------------------------------------------------------
@@ -51,13 +36,11 @@
5136
""", re.VERBOSE)
5237

5338

54-
def split_user_input(line, pattern=None):
39+
def split_user_input(line: str, pattern: re.Pattern[str] | None = None) -> tuple[str, str, str, str]:
5540
"""Split user input into initial whitespace, escape character, function part
5641
and the rest.
5742
"""
58-
# We need to ensure that the rest of this routine deals only with unicode
59-
encoding = get_stream_enc(sys.stdin, 'utf-8')
60-
line = py3compat.cast_unicode(line, encoding)
43+
assert isinstance(line, str)
6144

6245
if pattern is None:
6346
pattern = line_split
@@ -111,7 +94,19 @@ class LineInfo:
11194
raw_the_rest
11295
the_rest without whitespace stripped.
11396
"""
114-
def __init__(self, line, continue_prompt=False):
97+
98+
line: str
99+
continue_prompt: bool
100+
pre: str
101+
esc: str
102+
ifun: str
103+
raw_the_rest: str
104+
the_rest: str
105+
pre_char: str
106+
pre_whitespace: str
107+
108+
def __init__(self, line: str, continue_prompt: bool = False) -> None:
109+
assert isinstance(line, str)
115110
self.line = line
116111
self.continue_prompt = continue_prompt
117112
self.pre, self.esc, self.ifun, self.raw_the_rest = split_user_input(line)
@@ -138,8 +133,8 @@ def ofind(self, ip) -> OInfo:
138133
"""
139134
return ip._ofind(self.ifun)
140135

141-
def __str__(self):
136+
def __str__(self) -> str:
142137
return "LineInfo [%s|%s|%s|%s]" %(self.pre, self.esc, self.ifun, self.the_rest)
143138

144-
def __repr__(self):
139+
def __repr__(self) -> str:
145140
return "<" + str(self) + ">"

0 commit comments

Comments
 (0)