Skip to content

Commit

Permalink
Fix many py2-style prints in docs and commented code. (#14432)
Browse files Browse the repository at this point in the history
The main interest was to transform py2-style print statements that still
appeared in some docstrings (e.g. for %history) and would thus show up
when looking at the docs either interactively or in the rendered
website. I also fixed a number of commented-out print statements at the
same time, mostly because it was easier for me to just regexp-change all
of them so that I could focus on the others.
  • Loading branch information
Carreau committed May 13, 2024
2 parents 810faec + 7a8349b commit 1066e43
Show file tree
Hide file tree
Showing 30 changed files with 64 additions and 64 deletions.
4 changes: 2 additions & 2 deletions IPython/core/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def calljed(self,filename, linenum):
"My editor hook calls the jed editor directly."
print "Calling my own editor, jed ..."
print("Calling my own editor, jed ...")
if os.system('jed +%d %s' % (linenum,filename)) != 0:
raise TryNext()
Expand Down Expand Up @@ -111,7 +111,7 @@ def __call__(self,*args, **kw):
TryNext"""
last_exc = TryNext()
for prio,cmd in self.chain:
#print "prio",prio,"cmd",cmd #dbg
# print("prio",prio,"cmd",cmd) # dbg
try:
return cmd(*args, **kw)
except TryNext as exc:
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/inputsplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class InputSplitter(object):
prompt = '>>> ' + indent
line = indent + raw_input(prompt)
isp.push(line)
print 'Input source was:\n', isp.source_reset(),
print('Input source was:\n', isp.source_reset())
"""
# A cache for storing the current indentation
# The first value stores the most recently processed source input
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def log(self, line_mod, line_ori):
def log_write(self, data, kind='input'):
"""Write data to the log file, if active"""

#print 'data: %r' % data # dbg
# print('data: %r' % data) # dbg
if self.log_active and data:
write = self.logfile.write
if kind=='input':
Expand Down
12 changes: 6 additions & 6 deletions IPython/core/magics/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class DataIsObject(Exception): pass
# Load the parameter given as a variable. If not a string,
# process it as an object instead (below)

#print '*** args',args,'type',type(args) # dbg
# print('*** args',args,'type',type(args)) # dbg
data = eval(args, shell.user_ns)
if not isinstance(data, str):
raise DataIsObject
Expand Down Expand Up @@ -636,8 +636,8 @@ def edit(self, parameter_s='',last_call=['','']):
In [1]: edit
Editing... done. Executing edited code...
Out[1]: 'def foo():\\n print "foo() was defined in an editing
session"\\n'
Out[1]: 'def foo():\\n print("foo() was defined in an editing
session")\\n'
We can then call the function foo()::
Expand All @@ -661,21 +661,21 @@ def edit(self, parameter_s='',last_call=['','']):
In [5]: edit
Editing... done. Executing edited code...
hello
Out[5]: "print 'hello'\\n"
Out[5]: "print('hello')\\n"
Now we call it again with the previous output (stored in _)::
In [6]: edit _
Editing... done. Executing edited code...
hello world
Out[6]: "print 'hello world'\\n"
Out[6]: "print('hello world')\\n"
Now we call it with the output #8 (stored in _8, also as Out[8])::
In [7]: edit _8
Editing... done. Executing edited code...
hello again
Out[7]: "print 'hello again'\\n"
Out[7]: "print('hello again')\\n"
Changing the default editor hook:
Expand Down
10 changes: 5 additions & 5 deletions IPython/core/magics/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ def time(self,line='', cell=None, local_ns=None):
Wall time: 1.37
Out[3]: 499999500000L
In [4]: %time print 'hello world'
In [4]: %time print('hello world')
hello world
CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.00
Expand Down Expand Up @@ -1406,9 +1406,9 @@ def macro(self, parameter_s=''):
44: x=1
45: y=3
46: z=x+y
47: print x
47: print(x)
48: a=5
49: print 'x',x,'y',y
49: print('x',x,'y',y)
you can create a macro with lines 44 through 47 (included) and line 49
called my_macro with::
Expand All @@ -1428,7 +1428,7 @@ def macro(self, parameter_s=''):
You can view a macro's contents by explicitly printing it with::
print macro_name
print(macro_name)
"""
opts,args = self.parse_options(parameter_s,'rq',mode='list')
Expand All @@ -1439,7 +1439,7 @@ def macro(self, parameter_s=''):
"%macro insufficient args; usage '%macro name n1-n2 n3-4...")
name, codefrom = args[0], " ".join(args[1:])

#print 'rng',ranges # dbg
# print('rng',ranges) # dbg
try:
lines = self.shell.find_user_code(codefrom, 'r' in opts)
except (ValueError, TypeError) as e:
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/magics/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def history(self, parameter_s = ''):
In [6]: %history -n 4-6
4:a = 12
5:print a**2
5:print(a**2)
6:%history -n 4-6
"""
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/magics/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def pinfo(self, parameter_s='', namespaces=None):
'%pinfo object' is just a synonym for object? or ?object."""

#print 'pinfo par: <%s>' % parameter_s # dbg
# print('pinfo par: <%s>' % parameter_s) # dbg
# detail_level: 0 -> obj? , 1 -> obj??
detail_level = 0
# We need to detect if we got called as 'pinfo pinfo foo', which can
Expand Down
4 changes: 2 additions & 2 deletions IPython/core/oinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ def psearch(self,pattern,ns_table,ns_search=[],
- list_types(False): list all available object types for object matching.
"""
#print 'ps pattern:<%r>' % pattern # dbg
# print('ps pattern:<%r>' % pattern) # dbg

# defaults
type_pattern = 'all'
Expand Down Expand Up @@ -1225,7 +1225,7 @@ def psearch(self,pattern,ns_table,ns_search=[],
raise ValueError('invalid namespace <%s>. Valid names: %s' %
(name,ns_table.keys()))

#print 'type_pattern:',type_pattern # dbg
# print('type_pattern:',type_pattern) # dbg
search_result, namespaces_seen = set(), set()
for ns_name in ns_search:
ns = ns_table[ns_name]
Expand Down
8 changes: 4 additions & 4 deletions IPython/core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def _detect_screen_size(screen_lines_def):
termios.tcsetattr(sys.stdout,termios.TCSANOW,term_flags)
# Now we have what we needed: the screen size in rows/columns
return screen_lines_real
#print '***Screen size:',screen_lines_real,'lines x',\
#screen_cols,'columns.' # dbg
# print('***Screen size:',screen_lines_real,'lines x',
# screen_cols,'columns.') # dbg

def pager_page(strng, start=0, screen_lines=0, pager_cmd=None):
"""Display a string, piping through a pager after a certain length.
Expand Down Expand Up @@ -179,9 +179,9 @@ def pager_page(strng, start=0, screen_lines=0, pager_cmd=None):
print(str_toprint)
return

#print 'numlines',numlines,'screenlines',screen_lines # dbg
# print('numlines',numlines,'screenlines',screen_lines) # dbg
if numlines <= screen_lines :
#print '*** normal print' # dbg
# print('*** normal print') # dbg
print(str_toprint)
else:
# Try to open pager and default to internal one if that fails.
Expand Down
8 changes: 4 additions & 4 deletions IPython/core/prefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def prefilter_line_info(self, line_info):
This implements the checker/handler part of the prefilter pipe.
"""
# print "prefilter_line_info: ", line_info
# print("prefilter_line_info: ", line_info)
handler = self.find_handler(line_info)
return handler.handle(line_info)

Expand All @@ -267,7 +267,7 @@ def prefilter_line(self, line, continue_prompt=False):
transformers and then the checkers/handlers.
"""

# print "prefilter_line: ", line, continue_prompt
# print("prefilter_line: ", line, continue_prompt)
# All handlers *must* return a value, even if it's blank ('').

# save the line away in case we crash, so the post-mortem handler can
Expand Down Expand Up @@ -300,7 +300,7 @@ def prefilter_line(self, line, continue_prompt=False):
return normal_handler.handle(line_info)

prefiltered = self.prefilter_line_info(line_info)
# print "prefiltered line: %r" % prefiltered
# print("prefiltered line: %r" % prefiltered)
return prefiltered

def prefilter_lines(self, lines, continue_prompt=False):
Expand Down Expand Up @@ -544,7 +544,7 @@ def __init__(self, shell=None, prefilter_manager=None, **kwargs):
)

def handle(self, line_info):
# print "normal: ", line_info
# print("normal: ", line_info)
"""Handle normal input lines. Use as a template for handlers."""

# With autoindent on, we need some way to exit the input loop, and I
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/pylabtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def mpl_execfile(fname,*where,**kw):
import matplotlib
import matplotlib.pyplot as plt

#print '*** Matplotlib runner ***' # dbg
# print('*** Matplotlib runner ***') # dbg
# turn off rendering until end of script
with matplotlib.rc_context({"interactive": False}):
safe_execfile(fname, *where, **kw)
Expand Down
8 changes: 4 additions & 4 deletions IPython/core/splitinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ def split_user_input(line, pattern=None):
pattern = line_split
match = pattern.match(line)
if not match:
# print "match failed for line '%s'" % line
# print("match failed for line '%s'" % line)
try:
ifun, the_rest = line.split(None,1)
except ValueError:
# print "split failed for line '%s'" % line
# print("split failed for line '%s'" % line)
ifun, the_rest = line, u''
pre = re.match(r'^(\s*)(.*)',line).groups()[0]
esc = ""
else:
pre, esc, ifun, the_rest = match.groups()

#print 'line:<%s>' % line # dbg
#print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun.strip(),the_rest) # dbg
# print('line:<%s>' % line) # dbg
# print('pre <%s> ifun <%s> rest <%s>' % (pre,ifun.strip(),the_rest)) # dbg
return pre, esc or '', ifun.strip(), the_rest.lstrip()


Expand Down
2 changes: 1 addition & 1 deletion IPython/core/tests/tclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __del__(self):
if name.startswith('C'):
c = C(name)

#print >> sys.stderr, "ARGV:", sys.argv # dbg
# print("ARGV:", sys.argv, file=sys.stderr) # dbg

# This next print statement is NOT debugging, we're making the check on a
# completely separate process so we verify by capturing stdout:
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/tests/test_inputsplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def mini_interactive_loop(input_func):
# Here we just return input so we can use it in a test suite, but a real
# interpreter would instead send it for execution somewhere.
src = isp.source_reset()
#print 'Input source was:\n', src # dbg
# print('Input source was:\n', src) # dbg
return src

#-----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions IPython/extensions/storemagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def restore_aliases(ip, alias=None):
staliases = ip.db.get('stored_aliases', {})
if alias is None:
for k,v in staliases.items():
#print "restore alias",k,v # dbg
# print("restore alias",k,v) # dbg
#self.alias_table[k] = v
ip.alias_manager.define_alias(k,v)
else:
Expand All @@ -43,7 +43,7 @@ def refresh_variables(ip):
print("Unable to restore variable '%s', ignoring (use %%store -d to forget!)" % justkey)
print("The error was:", sys.exc_info()[0])
else:
#print "restored",justkey,"=",obj #dbg
# print("restored",justkey,"=",obj) # dbg
ip.user_ns[justkey] = obj


Expand Down
4 changes: 2 additions & 2 deletions IPython/lib/lexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ def get_mci(self, line):
# does not use the continuation marker cannot be detected.
# For example, the 3 in the following is clearly output:
#
# In [1]: print 3
# In [1]: print(3)
# 3
#
# But the following second line is part of the input:
#
# In [2]: while True:
# print True
# print(True)
#
# In both cases, the 2nd line will be 'output'.
#
Expand Down
6 changes: 3 additions & 3 deletions IPython/sphinxext/ipython_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def block_parser(part, rgxin, rgxout, fmtin, fmtout):

nextline = lines[i]
matchout = rgxout.match(nextline)
#print "nextline=%s, continuation=%s, starts=%s"%(nextline, continuation, nextline.startswith(continuation))
# print("nextline=%s, continuation=%s, starts=%s"%(nextline, continuation, nextline.startswith(continuation)))
if matchout or nextline.startswith('#'):
break
elif nextline.startswith(continuation):
Expand Down Expand Up @@ -538,7 +538,7 @@ def process_input(self, data, input_prompt, lineno):
# When there is stdout from the input, it also has a '\n' at the
# tail end, and so this ensures proper spacing as well. E.g.:
#
# In [1]: print x
# In [1]: print(x)
# 5
#
# In [2]: x = 5
Expand Down Expand Up @@ -699,7 +699,7 @@ def save_image(self, image_file):
"""
self.ensure_pyplot()
command = 'plt.gcf().savefig("%s")'%image_file
#print 'SAVEFIG', command # dbg
# print('SAVEFIG', command) # dbg
self.process_input_line('bookmark ipy_thisdir', store_history=False)
self.process_input_line('cd -b ipy_savedir', store_history=False)
self.process_input_line(command, store_history=False)
Expand Down
2 changes: 1 addition & 1 deletion IPython/terminal/ipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def initialize(self, argv=None):
if self.subapp is not None:
# don't bother initializing further, starting subapp
return
# print self.extra_args
# print(self.extra_args)
if self.extra_args and not self.something_to_run:
self.file_to_run = self.extra_args[0]
self.init_path()
Expand Down
4 changes: 2 additions & 2 deletions IPython/terminal/pt_inputhooks/glut.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def inputhook(context):
# 0.05 0.5%
used_time = clock() - t
if used_time > 10.0:
# print 'Sleep for 1 s' # dbg
# print('Sleep for 1 s') # dbg
time.sleep(1.0)
elif used_time > 0.1:
# Few GUI events coming in, so we can sleep longer
# print 'Sleep for 0.05 s' # dbg
# print('Sleep for 0.05 s') # dbg
time.sleep(0.05)
else:
# Many GUI events coming in, so sleep only very little
Expand Down
4 changes: 2 additions & 2 deletions IPython/terminal/pt_inputhooks/pyglet.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def inputhook(context):
# 0.05 0.5%
used_time = clock() - t
if used_time > 10.0:
# print 'Sleep for 1 s' # dbg
# print('Sleep for 1 s') # dbg
time.sleep(1.0)
elif used_time > 0.1:
# Few GUI events coming in, so we can sleep longer
# print 'Sleep for 0.05 s' # dbg
# print('Sleep for 0.05 s') # dbg
time.sleep(0.05)
else:
# Many GUI events coming in, so sleep only very little
Expand Down
4 changes: 2 additions & 2 deletions IPython/terminal/pt_inputhooks/wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def inputhook_wx3(context):
# 0.05 0.5%
used_time = clock() - t
if used_time > 10.0:
# print 'Sleep for 1 s' # dbg
# print('Sleep for 1 s') # dbg
time.sleep(1.0)
elif used_time > 0.1:
# Few GUI events coming in, so we can sleep longer
# print 'Sleep for 0.05 s' # dbg
# print('Sleep for 0.05 s') # dbg
time.sleep(0.05)
else:
# Many GUI events coming in, so sleep only very little
Expand Down
2 changes: 1 addition & 1 deletion IPython/testing/ipunittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __call__(self, ds):

newline(line)
newline('') # ensure a closing newline, needed by doctest
#print "PYSRC:", '\n'.join(out) # dbg
# print("PYSRC:", '\n'.join(out)) # dbg
return '\n'.join(out)

#return dnew
Expand Down

0 comments on commit 1066e43

Please sign in to comment.