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

Skip to content

Commit 74ed078

Browse files
authored
Merge branch 'main' into add-timeit-variable-capture
2 parents 46ea056 + 6cc4d06 commit 74ed078

12 files changed

Lines changed: 81 additions & 35 deletions

File tree

IPython/core/inputtransformer2.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import tokenize
1818
from typing import List, Tuple, Optional, Any
1919
import warnings
20+
from textwrap import dedent
2021

2122
from IPython.utils import tokenutil
2223

@@ -38,18 +39,11 @@ def leading_empty_lines(lines):
3839
def leading_indent(lines):
3940
"""Remove leading indentation.
4041
41-
If the first line starts with a spaces or tabs, the same whitespace will be
42-
removed from each following line in the cell.
42+
Removes the minimum common leading indentation from all lines.
4343
"""
4444
if not lines:
4545
return lines
46-
m = _indent_re.match(lines[0])
47-
if not m or lines[0].strip().startswith("#"):
48-
return lines
49-
space = m.group(0)
50-
n = len(space)
51-
return [l[n:] if l.startswith(space) else l
52-
for l in lines]
46+
return dedent("".join(lines)).splitlines(keepends=True)
5347

5448
class PromptStripper:
5549
"""Remove matching input prompts from a block of input.

IPython/core/interactiveshell.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ class InteractiveShell(SingletonConfigurable):
329329

330330
_instance = None
331331
_user_ns: dict
332+
_sys_modules_keys: set[str, AnyType]
332333

333334
inspector: oinspect.Inspector
334335

@@ -764,7 +765,9 @@ def _check_colors(self, proposal):
764765
if not new == new.lower():
765766
warn(
766767
f"`TerminalInteractiveShell.colors` is now lowercase: `{new.lower()}`,"
767-
" non lowercase, may invalid in the future."
768+
" non lowercase, may be invalid in the future.",
769+
DeprecationWarning,
770+
stacklevel=2,
768771
)
769772
return new.lower()
770773

@@ -781,7 +784,8 @@ def init_syntax_highlighting(self, changes=None):
781784
)
782785

783786
try:
784-
self.inspector.set_theme_name(self.colors)
787+
# Deprecation in 9.0, colors should always be lower
788+
self.inspector.set_theme_name(self.colors.lower())
785789
except Exception:
786790
warn(
787791
"Error changing object inspector color schemes.\n%s"
@@ -804,20 +808,19 @@ def init_pushd_popd_magic(self):
804808

805809
self.dir_stack = []
806810

807-
def init_logger(self):
811+
def init_logger(self) -> None:
808812
self.logger = Logger(self.home_dir, logfname='ipython_log.py',
809813
logmode='rotate')
810814

811-
def init_logstart(self):
815+
def init_logstart(self) -> None:
812816
"""Initialize logging in case it was requested at the command line.
813817
"""
814818
if self.logappend:
815-
self.magic('logstart %s append' % self.logappend)
819+
self.run_line_magic("logstart", f"{self.logappend} append")
816820
elif self.logfile:
817-
self.magic('logstart %s' % self.logfile)
821+
self.run_line_magic("logstart", self.logfile)
818822
elif self.logstart:
819-
self.magic('logstart')
820-
823+
self.run_line_magic("logstart", "")
821824

822825
def init_builtins(self):
823826
# A single, static flag that we set to True. Its presence indicates

IPython/core/oinspect.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,13 @@ def __init__(
401401
parent=None,
402402
config=None,
403403
):
404-
assert theme_name == theme_name.lower(), theme_name
404+
if theme_name in ["Linux", "LightBG", "Neutral", "NoColor"]:
405+
warnings.warn(
406+
f"Theme names and color schemes are lowercase in IPython 9.0 use {theme_name.lower()} instead",
407+
DeprecationWarning,
408+
stacklevel=2,
409+
)
410+
theme_name = theme_name.lower()
405411
self._theme_name = theme_name
406412
super(Inspector, self).__init__(parent=parent, config=config)
407413
self.parser = PyColorize.Parser(out="str", theme_name=theme_name)

IPython/core/tbtools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,13 @@ def __init__(
401401
stacklevel=2,
402402
)
403403
theme_name = color_scheme
404-
assert theme_name.lower() == theme_name, theme_name
404+
if theme_name in ["Linux", "LightBG", "Neutral", "NoColor"]:
405+
warnings.warn(
406+
f"Theme names and color schemes are lowercase in IPython 9.0 use {theme_name.lower()} instead",
407+
DeprecationWarning,
408+
stacklevel=2,
409+
)
410+
theme_name = theme_name.lower()
405411
# Whether to call the interactive pdb debugger after printing
406412
# tracebacks or not
407413
super().__init__()

IPython/terminal/pt_inputhooks/qt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ def inputhook(context):
5050
except AttributeError: # Only for Qt>=5.14.
5151
pass
5252
_appref = app = QtGui.QApplication([" "])
53-
_eventloop = QtCore.QEventLoop(app)
5453

5554
# "reclaim" IPython sys.excepthook after event loop starts
5655
# without this, it defaults back to BaseIPythonApplication.excepthook
5756
# and exceptions in the Qt event loop are rendered without traceback
5857
# formatting and look like "bug in IPython".
5958
QtCore.QTimer.singleShot(0, _reclaim_excepthook)
6059

60+
if _eventloop is None:
61+
_eventloop = QtCore.QEventLoop(app)
62+
6163
if sys.platform == 'win32':
6264
# The QSocketNotifier method doesn't appear to work on Windows.
6365
# Use polling instead.

IPython/terminal/shortcuts/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def create_identifier(handler: Callable):
203203
Binding(
204204
auto_suggest.accept,
205205
["right"],
206-
"has_suggestion & default_buffer_focused & emacs_like_insert_mode",
206+
"has_suggestion & default_buffer_focused & emacs_like_insert_mode & is_cursor_at_the_end_of_line",
207207
),
208208
Binding(
209209
auto_suggest.accept_word,

IPython/utils/PyColorize.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import token
55
import tokenize
6+
import warnings
67
from io import StringIO
78
from typing import TypeAlias
89

@@ -353,15 +354,20 @@ def __init__(self, out=sys.stdout, *, theme_name: str = None):
353354
Call format() to process code.
354355
"""
355356

356-
357357
assert theme_name is not None
358358

359359
self.out = out
360360
self.pos = None
361361
self.lines = None
362362
self.raw = None
363363
if theme_name is not None:
364-
assert theme_name == theme_name.lower()
364+
if theme_name in ["Linux", "LightBG", "Neutral", "NoColor"]:
365+
warnings.warn(
366+
f"Theme names and color schemes are lowercase in IPython 9.0 use {theme_name.lower()} instead",
367+
DeprecationWarning,
368+
stacklevel=2,
369+
)
370+
theme_name = theme_name.lower()
365371
if not theme_name:
366372
self.theme_name = "nocolor"
367373
else:

docs/source/config/intro.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Example configuration file
6868
'mycode.py',
6969
'fancy.ipy'
7070
]
71-
c.InteractiveShell.colors = 'LightBG'
71+
c.InteractiveShell.colors = 'lightbg'
7272
c.InteractiveShell.xmode = 'Context'
7373
c.TerminalInteractiveShell.confirm_exit = False
7474
c.TerminalInteractiveShell.editor = 'nano'
@@ -92,7 +92,7 @@ hierarchy represents the value you would normally set on the ``c`` object of
9292

9393
{
9494
"InteractiveShell": {
95-
"colors": "LightBG",
95+
"colors": "lightbg",
9696
},
9797
"InteractiveShellApp": {
9898
"extensions": [
@@ -106,7 +106,7 @@ hierarchy represents the value you would normally set on the ``c`` object of
106106

107107
Is equivalent to the following ``ipython_config.py``::
108108

109-
c.InteractiveShell.colors = 'LightBG'
109+
c.InteractiveShell.colors = 'lightbg'
110110
c.InteractiveShellApp.extensions = [
111111
'myextension'
112112
]

docs/source/whatsnew/version9.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ unicode symbol, for a more refined experience.
8484
New themes using colors and symbols
8585
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8686

87-
All the existing themes (Linux, LightBG, Neutral and Nocolor) should not see any
87+
All the existing themes (Linux, LightBG, Neutral and NoColor) should not see any
8888
changes, but I added two new *pride themes*, that show the use of 256bits colors
8989
and unicode symbols. I'm not a designer, so feel free to suggest updates and new
9090
themes to add.

examples/Embedding/start_ipython_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'import math',
1414
"math"
1515
]
16-
c.InteractiveShell.colors = 'LightBG'
16+
c.InteractiveShell.colors = "lightbg"
1717
c.InteractiveShell.confirm_exit = False
1818
c.TerminalIPythonApp.display_banner = False
1919

0 commit comments

Comments
 (0)