Skip to content

Commit

Permalink
Merge branch 'main' into shaperilio/autoreload-verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
shaperilio committed Jan 23, 2023
2 parents b70c007 + 855e459 commit ad33309
Show file tree
Hide file tree
Showing 14 changed files with 1,333 additions and 346 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ jobs:
pip install mypy pyflakes flake8
- name: Lint with mypy
run: |
set -e
mypy -p IPython.terminal
mypy -p IPython.core.magics
mypy -p IPython.core.guarded_eval
mypy -p IPython.core.completer
- name: Lint with pyflakes
run: |
set -e
flake8 IPython/core/magics/script.py
flake8 IPython/core/magics/packaging.py
5 changes: 2 additions & 3 deletions IPython/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ def load_subconfig(self, fname, path=None, profile=None):
return super(ProfileAwareConfigLoader, self).load_subconfig(fname, path=path)

class BaseIPythonApplication(Application):

name = u'ipython'
description = Unicode(u'IPython: an enhanced interactive Python shell.')
name = "ipython"
description = "IPython: an enhanced interactive Python shell."
version = Unicode(release.version)

aliases = base_aliases
Expand Down
77 changes: 57 additions & 20 deletions IPython/terminal/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys
from warnings import warn
from typing import Union as UnionType

from IPython.core.async_helpers import get_asyncio_loop
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
Expand Down Expand Up @@ -49,6 +50,10 @@
from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook
from .ptutils import IPythonPTCompleter, IPythonPTLexer
from .shortcuts import create_ipython_shortcuts
from .shortcuts.auto_suggest import (
NavigableAutoSuggestFromHistory,
AppendAutoSuggestionInAnyLine,
)

PTK3 = ptk_version.startswith('3.')

Expand Down Expand Up @@ -142,6 +147,10 @@ class PtkHistoryAdapter(History):
"""

auto_suggest: UnionType[
AutoSuggestFromHistory, NavigableAutoSuggestFromHistory, None
]

def __init__(self, shell):
super().__init__()
self.shell = shell
Expand Down Expand Up @@ -183,7 +192,7 @@ class TerminalInteractiveShell(InteractiveShell):
'menus, decrease for short and wide.'
).tag(config=True)

pt_app = None
pt_app: UnionType[PromptSession, None] = None
debugger_history = None

debugger_history_file = Unicode(
Expand Down Expand Up @@ -376,18 +385,27 @@ def _displayhook_class_default(self):
).tag(config=True)

autosuggestions_provider = Unicode(
"AutoSuggestFromHistory",
"NavigableAutoSuggestFromHistory",
help="Specifies from which source automatic suggestions are provided. "
"Can be set to `'AutoSuggestFromHistory`' or `None` to disable"
"automatic suggestions. Default is `'AutoSuggestFromHistory`'.",
"Can be set to ``'NavigableAutoSuggestFromHistory'`` (:kbd:`up` and "
":kbd:`down` swap suggestions), ``'AutoSuggestFromHistory'``, "
" or ``None`` to disable automatic suggestions. "
"Default is `'NavigableAutoSuggestFromHistory`'.",
allow_none=True,
).tag(config=True)

def _set_autosuggestions(self, provider):
# disconnect old handler
if self.auto_suggest and isinstance(
self.auto_suggest, NavigableAutoSuggestFromHistory
):
self.auto_suggest.disconnect()
if provider is None:
self.auto_suggest = None
elif provider == "AutoSuggestFromHistory":
self.auto_suggest = AutoSuggestFromHistory()
elif provider == "NavigableAutoSuggestFromHistory":
self.auto_suggest = NavigableAutoSuggestFromHistory()
else:
raise ValueError("No valid provider.")
if self.pt_app:
Expand Down Expand Up @@ -462,6 +480,8 @@ def prompt():
tempfile_suffix=".py",
**self._extra_prompt_options()
)
if isinstance(self.auto_suggest, NavigableAutoSuggestFromHistory):
self.auto_suggest.connect(self.pt_app)

def _make_style_from_name_or_cls(self, name_or_cls):
"""
Expand Down Expand Up @@ -560,23 +580,39 @@ def get_message():
get_message = get_message()

options = {
'complete_in_thread': False,
'lexer':IPythonPTLexer(),
'reserve_space_for_menu':self.space_for_menu,
'message': get_message,
'prompt_continuation': (
lambda width, lineno, is_soft_wrap:
PygmentsTokens(self.prompts.continuation_prompt_tokens(width))),
'multiline': True,
'complete_style': self.pt_complete_style,

"complete_in_thread": False,
"lexer": IPythonPTLexer(),
"reserve_space_for_menu": self.space_for_menu,
"message": get_message,
"prompt_continuation": (
lambda width, lineno, is_soft_wrap: PygmentsTokens(
self.prompts.continuation_prompt_tokens(width)
)
),
"multiline": True,
"complete_style": self.pt_complete_style,
"input_processors": [
# Highlight matching brackets, but only when this setting is
# enabled, and only when the DEFAULT_BUFFER has the focus.
'input_processors': [ConditionalProcessor(
processor=HighlightMatchingBracketProcessor(chars='[](){}'),
filter=HasFocus(DEFAULT_BUFFER) & ~IsDone() &
Condition(lambda: self.highlight_matching_brackets))],
}
ConditionalProcessor(
processor=HighlightMatchingBracketProcessor(chars="[](){}"),
filter=HasFocus(DEFAULT_BUFFER)
& ~IsDone()
& Condition(lambda: self.highlight_matching_brackets),
),
# Show auto-suggestion in lines other than the last line.
ConditionalProcessor(
processor=AppendAutoSuggestionInAnyLine(),
filter=HasFocus(DEFAULT_BUFFER)
& ~IsDone()
& Condition(
lambda: isinstance(
self.auto_suggest, NavigableAutoSuggestFromHistory
)
),
),
],
}
if not PTK3:
options['inputhook'] = self.inputhook

Expand Down Expand Up @@ -647,8 +683,9 @@ def init_alias(self):
self.alias_manager.soft_define_alias(cmd, cmd)


def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
self.auto_suggest = None
self._set_autosuggestions(self.autosuggestions_provider)
self.init_prompt_toolkit_cli()
self.init_term_title()
Expand Down
4 changes: 2 additions & 2 deletions IPython/terminal/ipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def make_report(self,traceback):
flags.update(frontend_flags)

aliases = dict(base_aliases)
aliases.update(shell_aliases)
aliases.update(shell_aliases) # type: ignore[arg-type]

#-----------------------------------------------------------------------------
# Main classes and functions
Expand All @@ -180,7 +180,7 @@ def start(self):
class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
name = u'ipython'
description = usage.cl_usage
crash_handler_class = IPAppCrashHandler
crash_handler_class = IPAppCrashHandler # typing: ignore[assignment]
examples = _examples

flags = flags
Expand Down
Loading

0 comments on commit ad33309

Please sign in to comment.