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

Skip to content

Commit 1a7986e

Browse files
committed
deprecate and ruff format the file
1 parent c2dc68b commit 1a7986e

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

IPython/core/prefilter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def check(self, line_info):
498498
if not self.shell.autocall:
499499
return None
500500

501-
oinfo = line_info.ofind(self.shell) # This can mutate state via getattr
501+
oinfo = self.shell._ofind(line_info.ifun) # This can mutate state via getattr
502502
if not oinfo.found:
503503
return None
504504

@@ -610,7 +610,7 @@ def handle(self, line_info):
610610
the_rest = line_info.the_rest
611611
esc = line_info.esc
612612
continue_prompt = line_info.continue_prompt
613-
obj = line_info.ofind(self.shell).obj
613+
obj = self.shell._ofind(line_info.ifun).obj
614614

615615
# This should only be active for single-line input!
616616
if continue_prompt:

IPython/core/splitinput.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
prefilter.
44
"""
55

6-
#-----------------------------------------------------------------------------
6+
# -----------------------------------------------------------------------------
77
# Imports
8-
#-----------------------------------------------------------------------------
8+
# -----------------------------------------------------------------------------
99

1010
import re
1111
import sys
12+
import warnings
1213

1314
from IPython.core.oinspect import OInfo
1415

15-
#-----------------------------------------------------------------------------
16+
# -----------------------------------------------------------------------------
1617
# Main function
17-
#-----------------------------------------------------------------------------
18+
# -----------------------------------------------------------------------------
1819

1920
# RegExp for splitting line contents into pre-char//first word-method//rest.
2021
# For clarity, each group in on one line.
@@ -27,16 +28,21 @@
2728
# ! and !! trigger if they are first char(s) *or* follow an indent
2829
# ? triggers as first or last char.
2930

30-
line_split = re.compile(r"""
31+
line_split = re.compile(
32+
r"""
3133
^(\s*) # any leading space
3234
([,;/%]|!!?|\?\??)? # escape character or characters
3335
\s*(%{0,2}[\w\.\*]*) # function/method, possibly with leading %
3436
# to correctly treat things like '?%magic'
3537
(.*?$|$) # rest of line
36-
""", re.VERBOSE)
38+
""",
39+
re.VERBOSE,
40+
)
3741

3842

39-
def split_user_input(line: str, pattern: re.Pattern[str] | None = None) -> tuple[str, str, str, str]:
43+
def split_user_input(
44+
line: str, pattern: re.Pattern[str] | None = None
45+
) -> tuple[str, str, str, str]:
4046
"""Split user input into initial whitespace, escape character, function part
4147
and the rest.
4248
"""
@@ -48,11 +54,11 @@ def split_user_input(line: str, pattern: re.Pattern[str] | None = None) -> tuple
4854
if not match:
4955
# print("match failed for line '%s'" % line)
5056
try:
51-
ifun, the_rest = line.split(None,1)
57+
ifun, the_rest = line.split(None, 1)
5258
except ValueError:
5359
# print("split failed for line '%s'" % line)
54-
ifun, the_rest = line, u''
55-
pre = re.match(r'^(\s*)(.*)',line).groups()[0]
60+
ifun, the_rest = line, ""
61+
pre = re.match(r"^(\s*)(.*)", line).groups()[0]
5662
esc = ""
5763
else:
5864
pre, esc, ifun, the_rest = match.groups()
@@ -107,14 +113,14 @@ class LineInfo:
107113

108114
def __init__(self, line: str, continue_prompt: bool = False) -> None:
109115
assert isinstance(line, str)
110-
self.line = line
116+
self.line = line
111117
self.continue_prompt = continue_prompt
112118
self.pre, self.esc, self.ifun, self.raw_the_rest = split_user_input(line)
113119
self.the_rest = self.raw_the_rest.lstrip()
114120

115-
self.pre_char = self.pre.strip()
121+
self.pre_char = self.pre.strip()
116122
if self.pre_char:
117-
self.pre_whitespace = '' # No whitespace allowed before esc chars
123+
self.pre_whitespace = "" # No whitespace allowed before esc chars
118124
else:
119125
self.pre_whitespace = self.pre
120126

@@ -130,11 +136,20 @@ def ofind(self, ip) -> OInfo:
130136
131137
Does cache the results of the call, so can be called multiple times
132138
without worrying about *further* damaging state.
139+
140+
.. deprecated:: 9.8
141+
Use ``shell._ofind(line_info.ifun)`` directly instead.
133142
"""
143+
warnings.warn(
144+
"LineInfo.ofind() is deprecated since IPython 9.8. "
145+
"Use shell._ofind(line_info.ifun) directly instead.",
146+
DeprecationWarning,
147+
stacklevel=2,
148+
)
134149
return ip._ofind(self.ifun)
135150

136151
def __str__(self) -> str:
137-
return "LineInfo [%s|%s|%s|%s]" %(self.pre, self.esc, self.ifun, self.the_rest)
152+
return "LineInfo [%s|%s|%s|%s]" % (self.pre, self.esc, self.ifun, self.the_rest)
138153

139154
def __repr__(self) -> str:
140155
return "<" + str(self) + ">"

0 commit comments

Comments
 (0)