diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-06-09 18:57:13 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-06-09 18:57:13 -0400 |
commit | 6f06dd97b30ba2bed40d580f3dc966dc9be103fd (patch) | |
tree | d9ebaa6b5b91dee56b7e204807ad610a4e39d944 /cmd2/utils.py | |
parent | dd299bf5bf21b175ffdd2caae63cfa8bf1a85c34 (diff) | |
download | cmd2-git-6f06dd97b30ba2bed40d580f3dc966dc9be103fd.tar.gz |
Working on improving type hinting
Also:
- Refactored perror() to remove a rarely used optional argument which was unecessary
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 07969ff1..84b09168 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -8,6 +8,7 @@ from typing import Optional from . import constants + def strip_ansi(text: str) -> str: """Strip ANSI escape codes from a string. @@ -58,6 +59,7 @@ def namedtuple_with_defaults(typename, field_names, default_values=()): T.__new__.__defaults__ = tuple(prototype) return T + def namedtuple_with_two_defaults(typename, field_names, default_values=('', '')): """Wrapper around namedtuple which lets you treat the last value as optional. @@ -72,6 +74,7 @@ def namedtuple_with_two_defaults(typename, field_names, default_values=('', '')) T.__new__.__defaults__ = default_values return T + def cast(current, new): """Tries to force a new value into the same type as the current when trying to set the value for a parameter. @@ -101,6 +104,7 @@ def cast(current, new): print("Problem setting parameter (now %s) to %s; incorrect type?" % (current, new)) return current + def which(editor: str) -> Optional[str]: """Find the full path of a given editor. @@ -118,7 +122,8 @@ def which(editor: str) -> Optional[str]: editor_path = None return editor_path -def is_text_file(file_path): + +def is_text_file(file_path: str) -> bool: """Returns if a file contains only ASCII or UTF-8 encoded text :param file_path: path to the file being checked |