@@ -1984,7 +1984,7 @@ def _perform_completion(
1984
1984
# Save the quote so we can add a matching closing quote later.
1985
1985
completion_token_quote = raw_completion_token [0 ]
1986
1986
1987
- # readline still performs word breaks after a quote. Therefore something like quoted search
1987
+ # readline still performs word breaks after a quote. Therefore, something like quoted search
1988
1988
# text with a space would have resulted in begidx pointing to the middle of the token we
1989
1989
# we want to complete. Figure out where that token actually begins and save the beginning
1990
1990
# portion of it that was not part of the text readline gave us. We will remove it from the
@@ -2064,7 +2064,7 @@ def complete( # type: ignore[override]
2064
2064
until it returns a non-string value. It should return the next possible completion starting with text.
2065
2065
2066
2066
Since readline suppresses any exception raised in completer functions, they can be difficult to debug.
2067
- Therefore this function wraps the actual tab completion logic and prints to stderr any exception that
2067
+ Therefore, this function wraps the actual tab completion logic and prints to stderr any exception that
2068
2068
occurs before returning control to readline.
2069
2069
2070
2070
:param text: the current word that user is typing
@@ -2097,7 +2097,7 @@ def complete( # type: ignore[override]
2097
2097
begidx = max (readline .get_begidx () - num_stripped , 0 )
2098
2098
endidx = max (readline .get_endidx () - num_stripped , 0 )
2099
2099
2100
- # Shortcuts are not word break characters when tab completing. Therefore shortcuts become part
2100
+ # Shortcuts are not word break characters when tab completing. Therefore, shortcuts become part
2101
2101
# of the text variable if there isn't a word break, like a space, after it. We need to remove it
2102
2102
# from text and update the indexes. This only applies if we are at the beginning of the command line.
2103
2103
shortcut_to_restore = ''
@@ -4056,7 +4056,7 @@ def do_shell(self, args: argparse.Namespace) -> None:
4056
4056
# sh reports an incorrect return code for some applications when Ctrl-C is pressed within that
4057
4057
# application (e.g. less). Since sh received the SIGINT, it sets the return code to reflect being
4058
4058
# closed by SIGINT even though less did not exit upon a Ctrl-C press. In the same situation, other
4059
- # shells like bash and zsh report the actual return code of less. Therefore we will try to run the
4059
+ # shells like bash and zsh report the actual return code of less. Therefore, we will try to run the
4060
4060
# user's preferred shell which most likely will be something other than sh. This also allows the user
4061
4061
# to run builtin commands of their preferred shell.
4062
4062
shell = os .environ .get ("SHELL" )
@@ -4103,7 +4103,7 @@ def _reset_py_display() -> None:
4103
4103
console to create its own display settings since they won't exist.
4104
4104
4105
4105
IPython does not have this problem since it always overwrites the display settings when it
4106
- is run. Therefore this method only needs to be called before creating a Python console.
4106
+ is run. Therefore, this method only needs to be called before creating a Python console.
4107
4107
"""
4108
4108
# Delete any prompts that have been set
4109
4109
attributes = ['ps1' , 'ps2' , 'ps3' ]
@@ -4318,7 +4318,7 @@ def py_quit() -> None:
4318
4318
saved_cmd2_env = self ._set_up_py_shell_env (interp )
4319
4319
4320
4320
# Since quit() or exit() raise an EmbeddedConsoleExit, interact() exits before printing
4321
- # the exitmsg. Therefore we will not provide it one and print it manually later.
4321
+ # the exitmsg. Therefore, we will not provide it one and print it manually later.
4322
4322
interp .interact (banner = banner , exitmsg = '' )
4323
4323
except BaseException :
4324
4324
# We don't care about any exception that happened in the interactive console
@@ -4453,7 +4453,7 @@ def do_ipy(self, _: argparse.Namespace) -> Optional[bool]: # pragma: no cover
4453
4453
4454
4454
# The IPython application is a singleton and won't be recreated next time
4455
4455
# this function runs. That's a problem since the contents of local_vars
4456
- # may need to be changed. Therefore we must destroy all instances of the
4456
+ # may need to be changed. Therefore, we must destroy all instances of the
4457
4457
# relevant classes.
4458
4458
TerminalIPythonApp .clear_instance ()
4459
4459
TerminalInteractiveShell .clear_instance ()
@@ -5026,14 +5026,22 @@ def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None:
5026
5026
text and cursor location is left alone.
5027
5027
5028
5028
IMPORTANT: This function will not print an alert unless it can acquire self.terminal_lock to ensure
5029
- a prompt is onscreen. Therefore it is best to acquire the lock before calling this function
5029
+ a prompt is onscreen. Therefore, it is best to acquire the lock before calling this function
5030
5030
to guarantee the alert prints and to avoid raising a RuntimeError.
5031
5031
5032
+ This function is only needed when you need to print an alert while the main thread is blocking
5033
+ at the prompt. Therefore, this should never be called from the main thread. Doing so will
5034
+ raise a RuntimeError.
5035
+
5032
5036
:param alert_msg: the message to display to the user
5033
5037
:param new_prompt: If you also want to change the prompt that is displayed, then include it here.
5034
5038
See async_update_prompt() docstring for guidance on updating a prompt.
5039
+ :raises RuntimeError: if called from the main thread.
5035
5040
:raises RuntimeError: if called while another thread holds `terminal_lock`
5036
5041
"""
5042
+ if threading .current_thread () is threading .main_thread ():
5043
+ raise RuntimeError ("async_alert should not be called from the main thread" )
5044
+
5037
5045
if not (vt100_support and self .use_rawinput ):
5038
5046
return
5039
5047
@@ -5096,14 +5104,19 @@ def async_update_prompt(self, new_prompt: str) -> None: # pragma: no cover
5096
5104
be shifted and the update will not be seamless.
5097
5105
5098
5106
IMPORTANT: This function will not update the prompt unless it can acquire self.terminal_lock to ensure
5099
- a prompt is onscreen. Therefore it is best to acquire the lock before calling this function
5107
+ a prompt is onscreen. Therefore, it is best to acquire the lock before calling this function
5100
5108
to guarantee the prompt changes and to avoid raising a RuntimeError.
5101
5109
5110
+ This function is only needed when you need to update the prompt while the main thread is blocking
5111
+ at the prompt. Therefore, this should never be called from the main thread. Doing so will
5112
+ raise a RuntimeError.
5113
+
5102
5114
If user is at a continuation prompt while entering a multiline command, the onscreen prompt will
5103
- not change. However self.prompt will still be updated and display immediately after the multiline
5115
+ not change. However, self.prompt will still be updated and display immediately after the multiline
5104
5116
line command completes.
5105
5117
5106
5118
:param new_prompt: what to change the prompt to
5119
+ :raises RuntimeError: if called from the main thread.
5107
5120
:raises RuntimeError: if called while another thread holds `terminal_lock`
5108
5121
"""
5109
5122
self .async_alert ('' , new_prompt )
@@ -5113,7 +5126,7 @@ def set_window_title(title: str) -> None: # pragma: no cover
5113
5126
"""
5114
5127
Set the terminal window title.
5115
5128
5116
- NOTE: This function writes to stderr. Therefore if you call this during a command run by a pyscript,
5129
+ NOTE: This function writes to stderr. Therefore, if you call this during a command run by a pyscript,
5117
5130
the string which updates the title will appear in that command's CommandResult.stderr data.
5118
5131
5119
5132
:param title: the new window title
0 commit comments