[Python-checkins] cpython: Issue #20390: Final fix, for generating NoPositional/NoKeyword for __init__

larry.hastings python-checkins at python.org
Sun Jan 26 07:01:39 CET 2014


http://hg.python.org/cpython/rev/1435d2fe8e34
changeset:   88721:1435d2fe8e34
user:        Larry Hastings <larry at hastings.org>
date:        Sat Jan 25 22:01:12 2014 -0800
summary:
  Issue #20390: Final fix, for generating NoPositional/NoKeyword for __init__ calls.

files:
  Misc/NEWS                     |   2 +-
  Modules/clinic/_bz2module.c.h |  11 +++++++----
  Tools/clinic/clinic.py        |  20 +++++++++++++++-----
  3 files changed, 23 insertions(+), 10 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -133,7 +133,7 @@
 IDLE
 ----
 
---Issue #17390: Add Python version to Idle editor window title bar.
+- Issue #17390: Add Python version to Idle editor window title bar.
   Original patches by Edmond Burnett and Kent Johnson.
 
 - Issue #18960: IDLE now ignores the source encoding declaration on the second
diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h
--- a/Modules/clinic/_bz2module.c.h
+++ b/Modules/clinic/_bz2module.c.h
@@ -75,7 +75,8 @@
     int return_value = -1;
     int compresslevel = 9;
 
-    if (!_PyArg_NoKeywords("BZ2Compressor", kwargs))
+    if ((Py_TYPE(self) == &BZ2Compressor_Type) &&
+        !_PyArg_NoKeywords("BZ2Compressor", kwargs))
         goto exit;
     if (!PyArg_ParseTuple(args,
         "|i:BZ2Compressor",
@@ -137,13 +138,15 @@
 {
     int return_value = -1;
 
-    if (!_PyArg_NoPositional("BZ2Decompressor", args))
+    if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
+        !_PyArg_NoPositional("BZ2Decompressor", args))
         goto exit;
-    if (!_PyArg_NoKeywords("BZ2Decompressor", kwargs))
+    if ((Py_TYPE(self) == &BZ2Decompressor_Type) &&
+        !_PyArg_NoKeywords("BZ2Decompressor", kwargs))
         goto exit;
     return_value = _bz2_BZ2Decompressor___init___impl((BZ2Decompressor *)self);
 
 exit:
     return return_value;
 }
-/*[clinic end generated code: checksum=9bb33ae7d35494b7a5365f03f390e4b5b8b1bc49]*/
+/*[clinic end generated code: checksum=4ade1dba3921a8bd8a614e5417f7654d8fb10be5]*/
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -2593,11 +2593,21 @@
     def set_template_dict(self, template_dict):
         template_dict['self_name'] = self.name
         template_dict['self_type'] = self.parser_type
-        if ((self.function.kind == METHOD_NEW) and
-            self.function.cls and
-            self.function.cls.typedef):
-            template_dict['self_type_object'] = self.function.cls.type_object
-            template_dict['self_type_check'] = '({self_name} == {self_type_object}) &&\n        '.format_map(template_dict)
+        kind = self.function.kind
+        cls = self.function.cls
+
+        if ((kind in (METHOD_NEW, METHOD_INIT)) and cls and cls.typedef):
+            if kind == METHOD_NEW:
+                passed_in_type = self.name
+            else:
+                passed_in_type = 'Py_TYPE({})'.format(self.name)
+
+            line = '({passed_in_type} == {type_object}) &&\n        '
+            d = {
+                'type_object': self.function.cls.type_object,
+                'passed_in_type': passed_in_type
+                }
+            template_dict['self_type_check'] = line.format_map(d)
 
 
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list