summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2018-06-08 12:46:31 +0900
committerYury Selivanov <yury@magic.io>2018-06-07 23:46:31 -0400
commit4aa3006619392438b0775a2f488bbe9e7a22c468 (patch)
tree170e855055da5cd7779432234cdb2085a0b5f685 /Lib
parentee994d7443a7e2809a5d49bd3679fc9c451a411b (diff)
downloadcpython-git-4aa3006619392438b0775a2f488bbe9e7a22c468.tar.gz
bpo-33197: Add description property for _ParameterKind. (GH-7206)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/inspect.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 409c05880d..8dad817b29 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2395,6 +2395,9 @@ class _ParameterKind(enum.IntEnum):
def __str__(self):
return self._name_
+ @property
+ def description(self):
+ return _PARAM_NAME_MAPPING[self]
_POSITIONAL_ONLY = _ParameterKind.POSITIONAL_ONLY
_POSITIONAL_OR_KEYWORD = _ParameterKind.POSITIONAL_OR_KEYWORD
@@ -2410,8 +2413,6 @@ _PARAM_NAME_MAPPING = {
_VAR_KEYWORD: 'variadic keyword'
}
-_get_paramkind_descr = _PARAM_NAME_MAPPING.__getitem__
-
class Parameter:
"""Represents a parameter in a function signature.
@@ -2453,7 +2454,7 @@ class Parameter:
if default is not _empty:
if self._kind in (_VAR_POSITIONAL, _VAR_KEYWORD):
msg = '{} parameters cannot have default values'
- msg = msg.format(_get_paramkind_descr(self._kind))
+ msg = msg.format(self._kind.description)
raise ValueError(msg)
self._default = default
self._annotation = annotation
@@ -2475,7 +2476,7 @@ class Parameter:
'implicit arguments must be passed as '
'positional or keyword arguments, not {}'
)
- msg = msg.format(_get_paramkind_descr(self._kind))
+ msg = msg.format(self._kind.description)
raise ValueError(msg)
self._kind = _POSITIONAL_ONLY
name = 'implicit{}'.format(name[1:])
@@ -2751,8 +2752,8 @@ class Signature:
'wrong parameter order: {} parameter before {} '
'parameter'
)
- msg = msg.format(_get_paramkind_descr(top_kind),
- _get_paramkind_descr(kind))
+ msg = msg.format(top_kind.description,
+ kind.description)
raise ValueError(msg)
elif kind > top_kind:
kind_defaults = False