summaryrefslogtreecommitdiffstats
path: root/Tools/clinic
diff options
context:
space:
mode:
authorLarry Hastings <larry@hastings.org>2013-11-18 17:32:13 (GMT)
committerLarry Hastings <larry@hastings.org>2013-11-18 17:32:13 (GMT)
commited4a1c57034d53bf217d64a771208d372ad9e1a5 (patch)
treea5448732832ef3315f33fba2f4b75f79358e4664 /Tools/clinic
parentfd32fffa5ada8b8be8a65bd51b001d989f99a3d3 (diff)
downloadcpython-ed4a1c57034d53bf217d64a771208d372ad9e1a5.zip
cpython-ed4a1c57034d53bf217d64a771208d372ad9e1a5.tar.gz
cpython-ed4a1c57034d53bf217d64a771208d372ad9e1a5.tar.bz2
Argument Clinic: rename "self" to "module" for module-level functions.
Diffstat (limited to 'Tools/clinic')
-rwxr-xr-xTools/clinic/clinic.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index cb4d6ab..ca87a44 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -127,13 +127,13 @@ is_legal_c_identifier = re.compile('^[A-Za-z_][A-Za-z0-9_]*$').match
def is_legal_py_identifier(s):
return all(is_legal_c_identifier(field) for field in s.split('.'))
-# added "self", "cls", and "null" just to be safe
+# added "module", "self", "cls", and "null" just to be safe
# (clinic will generate variables with these names)
c_keywords = set("""
asm auto break case char cls const continue default do double
-else enum extern float for goto if inline int long null register
-return self short signed sizeof static struct switch typedef
-typeof union unsigned void volatile while
+else enum extern float for goto if inline int long module null
+register return self short signed sizeof static struct switch
+typedef typeof union unsigned void volatile while
""".strip().split())
def ensure_legal_c_identifier(s):
@@ -620,7 +620,7 @@ static {impl_return_type}
else:
if f.kind == CALLABLE:
meth_flags = ''
- self_name = "self"
+ self_name = "self" if f.cls else "module"
elif f.kind == CLASS_METHOD:
meth_flags = 'METH_CLASS'
self_name = "cls"
@@ -1028,6 +1028,7 @@ class Clinic:
self.verify = verify
self.filename = filename
self.modules = collections.OrderedDict()
+ self.classes = collections.OrderedDict()
global clinic
clinic = self
@@ -1064,7 +1065,7 @@ class Clinic:
if not in_classes:
child = parent.modules.get(field)
if child:
- module = child
+ parent = module = child
continue
in_classes = True
if not hasattr(parent, 'classes'):
@@ -1129,6 +1130,9 @@ class Module:
self.classes = collections.OrderedDict()
self.functions = []
+ def __repr__(self):
+ return "<clinic.Module " + repr(self.name) + " at " + str(id(self)) + ">"
+
class Class:
def __init__(self, name, module=None, cls=None):
self.name = name
@@ -1139,6 +1143,10 @@ class Class:
self.classes = collections.OrderedDict()
self.functions = []
+ def __repr__(self):
+ return "<clinic.Class " + repr(self.name) + " at " + str(id(self)) + ">"
+
+
DATA, CALLABLE, METHOD, STATIC_METHOD, CLASS_METHOD = range(5)
class Function:
@@ -1808,13 +1816,11 @@ class DSLParser:
so_far = []
module, cls = self.clinic._module_and_class(fields)
- if not module:
- fail("You must explicitly specify the module for the class.")
-
c = Class(name, module, cls)
- module.classes[name] = c
if cls:
cls.classes[name] = c
+ else:
+ module.classes[name] = c
self.block.signatures.append(c)
def at_classmethod(self):