33prefilter.
44"""
55
6- #-----------------------------------------------------------------------------
6+ # -----------------------------------------------------------------------------
77# Imports
8- #-----------------------------------------------------------------------------
8+ # -----------------------------------------------------------------------------
99
1010import re
1111import sys
12+ import warnings
1213
1314from 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.
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