Skip to content

Commit 9d81810

Browse files
kmvanbruntanselor
authored andcommitted
Removed DEFAULT_ARGUMENT_PARSER and DEFAULT_COMMAND_COMPLETER from __init.py__
1 parent 70846b5 commit 9d81810

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

cmd2/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
set_default_argument_parser,
2929
)
3030

31-
# Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER
31+
# Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER.
32+
# Do this before loading cmd2.Cmd class so its commands use the custom parser.
3233
import argparse
3334

3435
cmd2_parser_module = getattr(argparse, 'cmd2_parser_module', None)
@@ -37,10 +38,8 @@
3738

3839
importlib.import_module(cmd2_parser_module)
3940

40-
from .argparse_completer import DEFAULT_COMMAND_COMPLETER, set_default_command_completer_type
41+
from .argparse_completer import set_default_command_completer_type
4142

42-
# Get the current value for argparse_custom.DEFAULT_ARGUMENT_PARSER
43-
from .argparse_custom import DEFAULT_ARGUMENT_PARSER
4443
from .cmd2 import Cmd
4544
from .command_definition import CommandSet, with_default_category
4645
from .constants import COMMAND_NAME, DEFAULT_SHORTCUTS
@@ -54,8 +53,6 @@
5453

5554
__all__: List[str] = [
5655
'COMMAND_NAME',
57-
'DEFAULT_ARGUMENT_PARSER',
58-
'DEFAULT_COMMAND_COMPLETER',
5956
'DEFAULT_SHORTCUTS',
6057
# ANSI Style exports
6158
'bg',

tests/test_argparse_custom.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,28 +247,26 @@ def test_apcustom_required_options():
247247

248248

249249
def test_override_parser():
250+
"""Test overriding argparse_custom.DEFAULT_ARGUMENT_PARSER"""
250251
import importlib
251252

252253
from cmd2 import (
253-
DEFAULT_ARGUMENT_PARSER,
254+
argparse_custom,
254255
)
255256

256257
# The standard parser is Cmd2ArgumentParser
257-
assert DEFAULT_ARGUMENT_PARSER == Cmd2ArgumentParser
258+
assert argparse_custom.DEFAULT_ARGUMENT_PARSER == Cmd2ArgumentParser
258259

259260
# Set our parser module and force a reload of cmd2 so it loads the module
260261
argparse.cmd2_parser_module = 'examples.custom_parser'
261262
importlib.reload(cmd2)
262-
from cmd2 import (
263-
DEFAULT_ARGUMENT_PARSER,
264-
)
265263

266264
# Verify DEFAULT_ARGUMENT_PARSER is now our CustomParser
267265
from examples.custom_parser import (
268266
CustomParser,
269267
)
270268

271-
assert DEFAULT_ARGUMENT_PARSER == CustomParser
269+
assert argparse_custom.DEFAULT_ARGUMENT_PARSER == CustomParser
272270

273271

274272
def test_apcustom_metavar_tuple():

0 commit comments

Comments
 (0)