From 6ba8d96321bf4052105f6f7fb6027d9e7073ea6c Mon Sep 17 00:00:00 2001 From: Todd Leonhardt Date: Sun, 10 Jun 2018 15:26:39 -0400 Subject: Added yet more type hinting --- cmd2/utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index 84b09168..11d48b78 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -4,7 +4,7 @@ import collections import os -from typing import Optional +from typing import Any, List, Optional, Union from . import constants @@ -31,7 +31,8 @@ def strip_quotes(arg: str) -> str: return arg -def namedtuple_with_defaults(typename, field_names, default_values=()): +def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]], + default_values: collections.Iterable=()): """ Convenience function for defining a namedtuple with default values @@ -60,7 +61,8 @@ def namedtuple_with_defaults(typename, field_names, default_values=()): return T -def namedtuple_with_two_defaults(typename, field_names, default_values=('', '')): +def namedtuple_with_two_defaults(typename: str, field_names: Union[str, List[str]], + default_values: collections.Iterable=('', '')): """Wrapper around namedtuple which lets you treat the last value as optional. :param typename: str - type name for the Named tuple @@ -75,7 +77,7 @@ def namedtuple_with_two_defaults(typename, field_names, default_values=('', '')) return T -def cast(current, new): +def cast(current: Any, new: str) -> Any: """Tries to force a new value into the same type as the current when trying to set the value for a parameter. :param current: current value for the parameter, type varies -- cgit v1.2.1