summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2020-08-11 10:36:21 -0400
committeranselor <anselor@gmail.com>2020-08-11 13:01:25 -0400
commit831197cb0f89c28d00967be6e6dadf15ad147626 (patch)
tree57646257f4a067dd83a68f30e058ae719b72366e /cmd2/utils.py
parent115143a1a3626cd651d3d18affd13cd60e1d06c8 (diff)
downloadcmd2-git-831197cb0f89c28d00967be6e6dadf15ad147626.tar.gz
Minor fixes to enable Python 3.5.2 support
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 39dc6e2b..a2b1c854 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -13,7 +13,7 @@ import sys
import threading
import unicodedata
from enum import Enum
-from typing import Any, Callable, Dict, Iterable, List, Optional, TextIO, Type, Union
+from typing import Any, Callable, Dict, Iterable, List, Optional, TextIO, Union
from . import constants
@@ -1041,15 +1041,20 @@ def categorize(func: Union[Callable, Iterable[Callable]], category: str) -> None
setattr(func, constants.CMD_ATTR_HELP_CATEGORY, category)
-def get_defining_class(meth: Callable) -> Optional[Type]:
+def get_defining_class(meth):
"""
Attempts to resolve the class that defined a method.
Inspired by implementation published here:
https://stackoverflow.com/a/25959545/1956611
+ TODO: Python 3.5.2 is unable to handle the type hints Callable and Optional[Type].
+ Restore proper type hints after we drop 3.5.2 support
+
:param meth: method to inspect
+ :type meth: Callable
:return: class type in which the supplied method was defined. None if it couldn't be resolved.
+ :rtype: Optional[Type]
"""
if isinstance(meth, functools.partial):
return get_defining_class(meth.func)