Skip to content

Commit 566f38c

Browse files
authored
Merge pull request #893 from python-cmd2/EmptyStatement_visibility
Empty statement visibility adjustment
2 parents 970c5fc + eecb0ac commit 566f38c

File tree

10 files changed

+25
-31
lines changed

10 files changed

+25
-31
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.10.1 (TBD)
1+
## 0.10.1 (February TBD, 2020)
22
* Bug Fixes
33
* Corrected issue where the actual new value was not always being printed in do_set. This occurred in cases where
44
the typed value differed from what the setter had converted it to.
@@ -19,6 +19,7 @@
1919
* Other
2020
* Removed undocumented `py run` command since it was replaced by `run_pyscript` a while ago
2121
* Renamed `AutoCompleter` to `ArgparseCompleter` for clarity
22+
* Custom `EmptyStatement` exception is no longer part of the documented public API
2223

2324
## 0.10.0 (February 7, 2020)
2425
* Enhancements

cmd2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# Get the current value for argparse_custom.DEFAULT_ARGUMENT_PARSER
2424
from .argparse_custom import DEFAULT_ARGUMENT_PARSER
25-
from .cmd2 import Cmd, EmptyStatement
25+
from .cmd2 import Cmd
2626
from .constants import COMMAND_NAME, DEFAULT_SHORTCUTS
2727
from .decorators import categorize, with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category
2828
from .parsing import Statement

cmd2/cmd2.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from .argparse_custom import CompletionItem, DEFAULT_ARGUMENT_PARSER
5151
from .clipboard import can_clip, get_paste_buffer, write_to_paste_buffer
5252
from .decorators import with_argparser
53+
from .exceptions import EmbeddedConsoleExit, EmptyStatement
5354
from .history import History, HistoryItem
5455
from .parsing import StatementParser, Statement, Macro, MacroArg, shlex_split
5556
from .rl_utils import rl_type, RlType, rl_get_point, rl_set_prompt, vt100_support, rl_make_safe_prompt, rl_warning
@@ -106,16 +107,6 @@ def __init__(self):
106107
self.sys_stdin = None
107108

108109

109-
class EmbeddedConsoleExit(SystemExit):
110-
"""Custom exception class for use with the py command."""
111-
pass
112-
113-
114-
class EmptyStatement(Exception):
115-
"""Custom exception class for handling behavior when the user just presses <Enter>."""
116-
pass
117-
118-
119110
# Contains data about a disabled command which is used to restore its original functions when the command is enabled
120111
DisabledCommand = namedtuple('DisabledCommand', ['command_function', 'help_function', 'completer_function'])
121112

cmd2/exceptions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# coding=utf-8
2+
"""Custom exceptions for cmd2. These are NOT part of the public API and are intended for internal use only."""
3+
4+
5+
class EmbeddedConsoleExit(SystemExit):
6+
"""Custom exception class for use with the py command."""
7+
pass
8+
9+
10+
class EmptyStatement(Exception):
11+
"""Custom exception class for handling behavior when the user just presses <Enter>."""
12+
pass

docs/api/exceptions.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/api/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ API Reference
66

77
cmd
88
decorators
9-
exceptions
109
ansi
1110
utility_classes
1211
utility_functions

docs/features/hooks.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@ called each time it was registered.
102102
Postparsing, precommand, and postcommand hook methods share some common ways to
103103
influence the command processing loop.
104104

105-
If a hook raises a ``cmd2.EmptyStatement`` exception:
106-
- no more hooks (except command finalization hooks) of any kind will be called
107-
- if the command has not yet been executed, it will not be executed
108-
- no error message will be displayed to the user
109-
110-
If a hook raises any other exception:
105+
If a hook raises an exception:
111106
- no more hooks (except command finalization hooks) of any kind will be called
112107
- if the command has not yet been executed, it will not be executed
113108
- the exception message will be displayed for the user.

tests/test_cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from unittest import mock
2121

2222
import cmd2
23-
from cmd2 import ansi, clipboard, constants, plugin, utils, COMMAND_NAME
23+
from cmd2 import ansi, clipboard, constants, exceptions, plugin, utils, COMMAND_NAME
2424
from .conftest import (run_cmd, normalize, verify_help_text, HELP_HISTORY, SHORTCUTS_TXT, SHOW_TXT,
2525
SHOW_LONG, complete_tester, odd_file_names)
2626

@@ -1258,7 +1258,7 @@ def multiline_app():
12581258
return app
12591259

12601260
def test_multiline_complete_empty_statement_raises_exception(multiline_app):
1261-
with pytest.raises(cmd2.EmptyStatement):
1261+
with pytest.raises(exceptions.EmptyStatement):
12621262
multiline_app._complete_statement('')
12631263

12641264
def test_multiline_complete_statement_without_terminator(multiline_app):

tests/test_parsing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88

99
import cmd2
10-
from cmd2 import constants, utils
10+
from cmd2 import constants, exceptions, utils
1111
from cmd2.parsing import StatementParser, shlex_split
1212

1313
@pytest.fixture
@@ -588,10 +588,10 @@ def test_parse_unclosed_quotes(parser):
588588

589589
def test_empty_statement_raises_exception():
590590
app = cmd2.Cmd()
591-
with pytest.raises(cmd2.EmptyStatement):
591+
with pytest.raises(exceptions.EmptyStatement):
592592
app._complete_statement('')
593593

594-
with pytest.raises(cmd2.EmptyStatement):
594+
with pytest.raises(exceptions.EmptyStatement):
595595
app._complete_statement(' ')
596596

597597
@pytest.mark.parametrize('line,command,args', [

tests/test_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from unittest import mock
1515

1616
import cmd2
17-
from cmd2 import plugin
17+
from cmd2 import exceptions, plugin
1818

1919

2020
class Plugin:
@@ -81,7 +81,7 @@ def postparse_hook_stop(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.
8181
def postparse_hook_emptystatement(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
8282
"""A postparsing hook with raises an EmptyStatement exception"""
8383
self.called_postparsing += 1
84-
raise cmd2.EmptyStatement
84+
raise exceptions.EmptyStatement
8585

8686
def postparse_hook_exception(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
8787
"""A postparsing hook which raises an exception"""
@@ -126,7 +126,7 @@ def precmd_hook(self, data: plugin.PrecommandData) -> plugin.PrecommandData:
126126
def precmd_hook_emptystatement(self, data: plugin.PrecommandData) -> plugin.PrecommandData:
127127
"""A precommand hook which raises an EmptyStatement exception"""
128128
self.called_precmd += 1
129-
raise cmd2.EmptyStatement
129+
raise exceptions.EmptyStatement
130130

131131
def precmd_hook_exception(self, data: plugin.PrecommandData) -> plugin.PrecommandData:
132132
"""A precommand hook which raises an exception"""

0 commit comments

Comments
 (0)