Skip to content

Commit cd8183d

Browse files
committed
Improved type hints and documentation in StatementParser.__init__()
1 parent 0a07689 commit cd8183d

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

cmd2/parsing.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import re
77
import shlex
8-
from typing import Dict, List, Tuple, Union
8+
from typing import Dict, Iterable, List, Optional, Tuple, Union
99

1010
import attr
1111

@@ -270,14 +270,25 @@ class StatementParser:
270270
Shortcuts is a list of tuples with each tuple containing the shortcut and
271271
the expansion.
272272
"""
273-
def __init__(
274-
self,
275-
allow_redirection: bool = True,
276-
terminators: List[str] = None,
277-
multiline_commands: List[str] = None,
278-
aliases: Dict[str, str] = None,
279-
shortcuts: List[Tuple[str, str]] = None,
280-
):
273+
def __init__(self,
274+
allow_redirection: bool = True,
275+
terminators: Optional[Iterable[str]] = None,
276+
multiline_commands: Optional[Iterable[str]] = None,
277+
aliases: Optional[Dict[str, str]] = None,
278+
shortcuts: Optional[Iterable[Tuple[str, str]]] = None) -> None:
279+
"""Initialize an instance of StatementParser.
280+
281+
The following will get converted to an immutable tuple before storing internally:
282+
* terminators
283+
* multiline commands
284+
* shortcuts
285+
286+
:param allow_redirection: (optional) should redirection and pipes be allowed?
287+
:param terminators: (optional) iterable containing strings which should terminate multiline commands
288+
:param multiline_commands: (optional) iterable containing the names of commands that accept multiline input
289+
:param aliases: (optional) dictionary contaiing aliases
290+
:param shortcuts (optional) an iterable of tuples with each tuple containing the shortcut and the expansion
291+
"""
281292
self.allow_redirection = allow_redirection
282293
if terminators is None:
283294
self.terminators = (constants.MULTILINE_TERMINATOR,)

0 commit comments

Comments
 (0)