summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2014-03-27 15:23:13 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2014-03-27 15:23:13 (GMT)
commit21e83a5564862d2a6d336c2896070ba5539bddcd (patch)
tree2efab278ed683ac7e05cc9204473d9d6c8f1e240 /Lib/inspect.py
parent4a692ce5ec362210c61de74979596feadc92d429 (diff)
downloadcpython-21e83a5564862d2a6d336c2896070ba5539bddcd.zip
cpython-21e83a5564862d2a6d336c2896070ba5539bddcd.tar.gz
cpython-21e83a5564862d2a6d336c2896070ba5539bddcd.tar.bz2
inspect.signature: Use enum for parameter kind constants. Closes #19573
Patch by Antony Lee.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index c7a2cf8..6054c39 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -32,6 +32,7 @@ __author__ = ('Ka-Ping Yee <ping@lfw.org>',
'Yury Selivanov <yselivanov@sprymix.com>')
import ast
+import enum
import importlib.machinery
import itertools
import linecache
@@ -2027,24 +2028,22 @@ class _empty:
pass
-class _ParameterKind(int):
- def __new__(self, *args, name):
- obj = int.__new__(self, *args)
- obj._name = name
- return obj
+class _ParameterKind(enum.IntEnum):
+ POSITIONAL_ONLY = 0
+ POSITIONAL_OR_KEYWORD = 1
+ VAR_POSITIONAL = 2
+ KEYWORD_ONLY = 3
+ VAR_KEYWORD = 4
def __str__(self):
- return self._name
-
- def __repr__(self):
- return '<_ParameterKind: {!r}>'.format(self._name)
+ return self._name_
-_POSITIONAL_ONLY = _ParameterKind(0, name='POSITIONAL_ONLY')
-_POSITIONAL_OR_KEYWORD = _ParameterKind(1, name='POSITIONAL_OR_KEYWORD')
-_VAR_POSITIONAL = _ParameterKind(2, name='VAR_POSITIONAL')
-_KEYWORD_ONLY = _ParameterKind(3, name='KEYWORD_ONLY')
-_VAR_KEYWORD = _ParameterKind(4, name='VAR_KEYWORD')
+_POSITIONAL_ONLY = _ParameterKind.POSITIONAL_ONLY
+_POSITIONAL_OR_KEYWORD = _ParameterKind.POSITIONAL_OR_KEYWORD
+_VAR_POSITIONAL = _ParameterKind.VAR_POSITIONAL
+_KEYWORD_ONLY = _ParameterKind.KEYWORD_ONLY
+_VAR_KEYWORD = _ParameterKind.VAR_KEYWORD
class Parameter: