summaryrefslogtreecommitdiffstats
path: root/Tools/clinic/clinic.py
diff options
context:
space:
mode:
authorLarry Hastings <larry@hastings.org>2014-01-07 20:13:13 (GMT)
committerLarry Hastings <larry@hastings.org>2014-01-07 20:13:13 (GMT)
commit77561cccb277f5347fc1c41a2fb06b7cc3194b8a (patch)
treec8a8adade248f1e9109f219041ce447e88ccb567 /Tools/clinic/clinic.py
parent16c5191ab3443aa5c1f835848514f94c696a8c4d (diff)
downloadcpython-77561cccb277f5347fc1c41a2fb06b7cc3194b8a.zip
cpython-77561cccb277f5347fc1c41a2fb06b7cc3194b8a.tar.gz
cpython-77561cccb277f5347fc1c41a2fb06b7cc3194b8a.tar.bz2
Issue #20141: Improved Argument Clinic's support for the PyArg_Parse "O!"
format unit.
Diffstat (limited to 'Tools/clinic/clinic.py')
-rwxr-xr-xTools/clinic/clinic.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 3b167ea..78600ee 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -1358,6 +1358,12 @@ class CConverter(metaclass=CConverterAutoRegister):
# by format units starting with 'e'.
encoding = None
+ # Should this object be required to be a subclass of a specific type?
+ # If not None, should be a string representing a pointer to a
+ # PyTypeObject (e.g. "&PyUnicode_Type").
+ # Only used by the 'O!' format unit (and the "object" converter).
+ subclass_of = None
+
# Do we want an adjacent '_length' variable for this variable?
# Only used by format units ending with '#'.
length = False
@@ -1446,7 +1452,9 @@ class CConverter(metaclass=CConverterAutoRegister):
list.append(self.converter)
if self.encoding:
- list.append(self.encoding)
+ list.append(c_repr(self.encoding))
+ elif self.subclass_of:
+ list.append(self.subclass_of)
legal_name = ensure_legal_c_identifier(self.name)
s = ("&" if self.parse_by_reference else "") + legal_name
@@ -1627,20 +1635,12 @@ class object_converter(CConverter):
type = 'PyObject *'
format_unit = 'O'
- def converter_init(self, *, type=None):
- if type:
- assert isinstance(type, str)
- assert type.isidentifier()
- try:
- type = eval(type)
- # need more of these!
- type = {
- str: '&PyUnicode_Type',
- }[type]
- except NameError:
- type = type
+ def converter_init(self, *, type=None, subclass_of=None):
+ if subclass_of:
self.format_unit = 'O!'
- self.encoding = type
+ self.subclass_of = subclass_of
+ if type is not None:
+ self.type = type
@add_legacy_c_converter('s#', length=True)