Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b7ccb204
Kaydet (Commit)
b7ccb204
authored
Ock 19, 2014
tarafından
Larry Hastings
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #20294: Argument Clinic now supports argument parsing for __new__ and
__init__ functions.
üst
b470575e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
51 deletions
+71
-51
clinic.rst
Doc/howto/clinic.rst
+21
-2
modsupport.h
Include/modsupport.h
+1
-0
NEWS
Misc/NEWS
+3
-0
_pickle.c
Modules/_pickle.c
+26
-48
getargs.c
Python/getargs.c
+20
-1
clinic.py
Tools/clinic/clinic.py
+0
-0
No files found.
Doc/howto/clinic.rst
Dosyayı görüntüle @
b7ccb204
...
@@ -784,8 +784,8 @@ Argument Clinic converters. On the left is the legacy converter,
...
@@ -784,8 +784,8 @@ Argument Clinic converters. On the left is the legacy converter,
on the right is the text you'd replace it with.
on the right is the text you'd replace it with.
========= =================================================================================
========= =================================================================================
``'B'`` ``
byte
(bitwise=True)``
``'B'`` ``
unsigned_char
(bitwise=True)``
``'b'`` ``
byte
``
``'b'`` ``
unsigned_char
``
``'c'`` ``char``
``'c'`` ``char``
``'C'`` ``int(types='str')``
``'C'`` ``int(types='str')``
``'d'`` ``double``
``'d'`` ``double``
...
@@ -1275,6 +1275,25 @@ any arguments.
...
@@ -1275,6 +1275,25 @@ any arguments.
You can still use a self converter, a return converter, and specify
You can still use a self converter, a return converter, and specify
a ``type`` argument to the object converter for ``METH_O``.
a ``type`` argument to the object converter for ``METH_O``.
tp_new and tp_init functions
----------------------------------------------
You can convert ``tp_new`` and ``tp_init``
functions. Just name them ``__new__`` or
``__init__`` as appropriate. Notes:
* The function name generated for ``__new__`` doesn't end in ``__new__``
like it would by default. It's just the name of the class, converted
into a valid C identifier.
* No ``PyMethodDef`` ``#define`` is generated for these functions.
* ``__init__`` functions return ``int``, not ``PyObject *``.
* Argument Clinic supports any signature for these functions, even though
the parsing function is required to always take ``args`` and ``kwargs``
objects.
The #ifdef trick
The #ifdef trick
----------------------------------------------
----------------------------------------------
...
...
Include/modsupport.h
Dosyayı görüntüle @
b7ccb204
...
@@ -36,6 +36,7 @@ PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
...
@@ -36,6 +36,7 @@ PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
#endif
#endif
#ifndef Py_LIMITED_API
#ifndef Py_LIMITED_API
PyAPI_FUNC
(
int
)
_PyArg_NoKeywords
(
const
char
*
funcname
,
PyObject
*
kw
);
PyAPI_FUNC
(
int
)
_PyArg_NoKeywords
(
const
char
*
funcname
,
PyObject
*
kw
);
PyAPI_FUNC
(
int
)
_PyArg_NoPositional
(
const
char
*
funcname
,
PyObject
*
args
);
PyAPI_FUNC
(
int
)
PyArg_VaParse
(
PyObject
*
,
const
char
*
,
va_list
);
PyAPI_FUNC
(
int
)
PyArg_VaParse
(
PyObject
*
,
const
char
*
,
va_list
);
PyAPI_FUNC
(
int
)
PyArg_VaParseTupleAndKeywords
(
PyObject
*
,
PyObject
*
,
PyAPI_FUNC
(
int
)
PyArg_VaParseTupleAndKeywords
(
PyObject
*
,
PyObject
*
,
...
...
Misc/NEWS
Dosyayı görüntüle @
b7ccb204
...
@@ -101,6 +101,9 @@ Tests
...
@@ -101,6 +101,9 @@ Tests
Tools/Demos
Tools/Demos
-----------
-----------
- Issue #20294: Argument Clinic now supports argument parsing for __new__ and
__init__ functions.
- Issue #20299: Argument Clinic custom converters may now change the default
- Issue #20299: Argument Clinic custom converters may now change the default
value of c_default and py_default with a class member.
value of c_default and py_default with a class member.
...
...
Modules/_pickle.c
Dosyayı görüntüle @
b7ccb204
...
@@ -4064,13 +4064,13 @@ PyDoc_STRVAR(_pickle_Pickler___init____doc__,
...
@@ -4064,13 +4064,13 @@ PyDoc_STRVAR(_pickle_Pickler___init____doc__,
"to map the new Python 3 names to the old module names used in Python
\n
"
"to map the new Python 3 names to the old module names used in Python
\n
"
"2, so that the pickle data stream is readable with Python 2."
);
"2, so that the pickle data stream is readable with Python 2."
);
static
PyObject
*
static
int
_pickle_Pickler___init___impl
(
PicklerObject
*
self
,
PyObject
*
file
,
PyObject
*
protocol
,
int
fix_imports
);
_pickle_Pickler___init___impl
(
PicklerObject
*
self
,
PyObject
*
file
,
PyObject
*
protocol
,
int
fix_imports
);
static
PyObject
*
static
int
_pickle_Pickler___init__
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
_pickle_Pickler___init__
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
{
PyObject
*
return_value
=
NULL
;
int
return_value
=
-
1
;
static
char
*
_keywords
[]
=
{
"file"
,
"protocol"
,
"fix_imports"
,
NULL
};
static
char
*
_keywords
[]
=
{
"file"
,
"protocol"
,
"fix_imports"
,
NULL
};
PyObject
*
file
;
PyObject
*
file
;
PyObject
*
protocol
=
NULL
;
PyObject
*
protocol
=
NULL
;
...
@@ -4086,9 +4086,9 @@ exit:
...
@@ -4086,9 +4086,9 @@ exit:
return
return_value
;
return
return_value
;
}
}
static
PyObject
*
static
int
_pickle_Pickler___init___impl
(
PicklerObject
*
self
,
PyObject
*
file
,
PyObject
*
protocol
,
int
fix_imports
)
_pickle_Pickler___init___impl
(
PicklerObject
*
self
,
PyObject
*
file
,
PyObject
*
protocol
,
int
fix_imports
)
/*[clinic end generated code: checksum=
defa3d9e9f8b51fb257d4fdfca99db503db0e6df
]*/
/*[clinic end generated code: checksum=
10c8ea05194d08108471163d8202cf5e12975544
]*/
{
{
_Py_IDENTIFIER
(
persistent_id
);
_Py_IDENTIFIER
(
persistent_id
);
_Py_IDENTIFIER
(
dispatch_table
);
_Py_IDENTIFIER
(
dispatch_table
);
...
@@ -4098,16 +4098,16 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *pro
...
@@ -4098,16 +4098,16 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *pro
(
void
)
Pickler_clear
(
self
);
(
void
)
Pickler_clear
(
self
);
if
(
_Pickler_SetProtocol
(
self
,
protocol
,
fix_imports
)
<
0
)
if
(
_Pickler_SetProtocol
(
self
,
protocol
,
fix_imports
)
<
0
)
return
NULL
;
return
-
1
;
if
(
_Pickler_SetOutputStream
(
self
,
file
)
<
0
)
if
(
_Pickler_SetOutputStream
(
self
,
file
)
<
0
)
return
NULL
;
return
-
1
;
/* memo and output_buffer may have already been created in _Pickler_New */
/* memo and output_buffer may have already been created in _Pickler_New */
if
(
self
->
memo
==
NULL
)
{
if
(
self
->
memo
==
NULL
)
{
self
->
memo
=
PyMemoTable_New
();
self
->
memo
=
PyMemoTable_New
();
if
(
self
->
memo
==
NULL
)
if
(
self
->
memo
==
NULL
)
return
NULL
;
return
-
1
;
}
}
self
->
output_len
=
0
;
self
->
output_len
=
0
;
if
(
self
->
output_buffer
==
NULL
)
{
if
(
self
->
output_buffer
==
NULL
)
{
...
@@ -4115,7 +4115,7 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *pro
...
@@ -4115,7 +4115,7 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *pro
self
->
output_buffer
=
PyBytes_FromStringAndSize
(
NULL
,
self
->
output_buffer
=
PyBytes_FromStringAndSize
(
NULL
,
self
->
max_output_len
);
self
->
max_output_len
);
if
(
self
->
output_buffer
==
NULL
)
if
(
self
->
output_buffer
==
NULL
)
return
NULL
;
return
-
1
;
}
}
self
->
fast
=
0
;
self
->
fast
=
0
;
...
@@ -4126,31 +4126,20 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *pro
...
@@ -4126,31 +4126,20 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *pro
self
->
pers_func
=
_PyObject_GetAttrId
((
PyObject
*
)
self
,
self
->
pers_func
=
_PyObject_GetAttrId
((
PyObject
*
)
self
,
&
PyId_persistent_id
);
&
PyId_persistent_id
);
if
(
self
->
pers_func
==
NULL
)
if
(
self
->
pers_func
==
NULL
)
return
NULL
;
return
-
1
;
}
}
self
->
dispatch_table
=
NULL
;
self
->
dispatch_table
=
NULL
;
if
(
_PyObject_HasAttrId
((
PyObject
*
)
self
,
&
PyId_dispatch_table
))
{
if
(
_PyObject_HasAttrId
((
PyObject
*
)
self
,
&
PyId_dispatch_table
))
{
self
->
dispatch_table
=
_PyObject_GetAttrId
((
PyObject
*
)
self
,
self
->
dispatch_table
=
_PyObject_GetAttrId
((
PyObject
*
)
self
,
&
PyId_dispatch_table
);
&
PyId_dispatch_table
);
if
(
self
->
dispatch_table
==
NULL
)
if
(
self
->
dispatch_table
==
NULL
)
return
NULL
;
return
-
1
;
}
}
Py_RETURN_NONE
;
}
/* Wrap the Clinic generated signature to slot it in tp_init. */
static
int
Pickler_init
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
PyObject
*
result
=
_pickle_Pickler___init__
(
self
,
args
,
kwargs
);
if
(
result
==
NULL
)
{
return
-
1
;
}
Py_DECREF
(
result
);
return
0
;
return
0
;
}
}
/* Define a proxy object for the Pickler's internal memo object. This is to
/* Define a proxy object for the Pickler's internal memo object. This is to
* avoid breaking code like:
* avoid breaking code like:
* pickler.memo.clear()
* pickler.memo.clear()
...
@@ -4543,7 +4532,7 @@ static PyTypeObject Pickler_Type = {
...
@@ -4543,7 +4532,7 @@ static PyTypeObject Pickler_Type = {
0
,
/*tp_descr_get*/
0
,
/*tp_descr_get*/
0
,
/*tp_descr_set*/
0
,
/*tp_descr_set*/
0
,
/*tp_dictoffset*/
0
,
/*tp_dictoffset*/
Pickler_init
,
/*tp_init*/
_pickle_Pickler___init__
,
/*tp_init*/
PyType_GenericAlloc
,
/*tp_alloc*/
PyType_GenericAlloc
,
/*tp_alloc*/
PyType_GenericNew
,
/*tp_new*/
PyType_GenericNew
,
/*tp_new*/
PyObject_GC_Del
,
/*tp_free*/
PyObject_GC_Del
,
/*tp_free*/
...
@@ -6614,13 +6603,13 @@ PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
...
@@ -6614,13 +6603,13 @@ PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
"respectively. The *encoding* can be
\'
bytes
\'
to read these 8-bit
\n
"
"respectively. The *encoding* can be
\'
bytes
\'
to read these 8-bit
\n
"
"string instances as bytes objects."
);
"string instances as bytes objects."
);
static
PyObject
*
static
int
_pickle_Unpickler___init___impl
(
UnpicklerObject
*
self
,
PyObject
*
file
,
int
fix_imports
,
const
char
*
encoding
,
const
char
*
errors
);
_pickle_Unpickler___init___impl
(
UnpicklerObject
*
self
,
PyObject
*
file
,
int
fix_imports
,
const
char
*
encoding
,
const
char
*
errors
);
static
PyObject
*
static
int
_pickle_Unpickler___init__
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
_pickle_Unpickler___init__
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
{
PyObject
*
return_value
=
NULL
;
int
return_value
=
-
1
;
static
char
*
_keywords
[]
=
{
"file"
,
"fix_imports"
,
"encoding"
,
"errors"
,
NULL
};
static
char
*
_keywords
[]
=
{
"file"
,
"fix_imports"
,
"encoding"
,
"errors"
,
NULL
};
PyObject
*
file
;
PyObject
*
file
;
int
fix_imports
=
1
;
int
fix_imports
=
1
;
...
@@ -6637,9 +6626,9 @@ exit:
...
@@ -6637,9 +6626,9 @@ exit:
return
return_value
;
return
return_value
;
}
}
static
PyObject
*
static
int
_pickle_Unpickler___init___impl
(
UnpicklerObject
*
self
,
PyObject
*
file
,
int
fix_imports
,
const
char
*
encoding
,
const
char
*
errors
)
_pickle_Unpickler___init___impl
(
UnpicklerObject
*
self
,
PyObject
*
file
,
int
fix_imports
,
const
char
*
encoding
,
const
char
*
errors
)
/*[clinic end generated code: checksum=
26c1d4a06841a8e51d29a0c244ba7f4607ff358a
]*/
/*[clinic end generated code: checksum=
6936e9188104e45b1b15e1c11fe77b3965409471
]*/
{
{
_Py_IDENTIFIER
(
persistent_load
);
_Py_IDENTIFIER
(
persistent_load
);
...
@@ -6648,20 +6637,20 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_i
...
@@ -6648,20 +6637,20 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_i
(
void
)
Unpickler_clear
(
self
);
(
void
)
Unpickler_clear
(
self
);
if
(
_Unpickler_SetInputStream
(
self
,
file
)
<
0
)
if
(
_Unpickler_SetInputStream
(
self
,
file
)
<
0
)
return
NULL
;
return
-
1
;
if
(
_Unpickler_SetInputEncoding
(
self
,
encoding
,
errors
)
<
0
)
if
(
_Unpickler_SetInputEncoding
(
self
,
encoding
,
errors
)
<
0
)
return
NULL
;
return
-
1
;
self
->
fix_imports
=
fix_imports
;
self
->
fix_imports
=
fix_imports
;
if
(
self
->
fix_imports
==
-
1
)
if
(
self
->
fix_imports
==
-
1
)
return
NULL
;
return
-
1
;
if
(
_PyObject_HasAttrId
((
PyObject
*
)
self
,
&
PyId_persistent_load
))
{
if
(
_PyObject_HasAttrId
((
PyObject
*
)
self
,
&
PyId_persistent_load
))
{
self
->
pers_func
=
_PyObject_GetAttrId
((
PyObject
*
)
self
,
self
->
pers_func
=
_PyObject_GetAttrId
((
PyObject
*
)
self
,
&
PyId_persistent_load
);
&
PyId_persistent_load
);
if
(
self
->
pers_func
==
NULL
)
if
(
self
->
pers_func
==
NULL
)
return
NULL
;
return
1
;
}
}
else
{
else
{
self
->
pers_func
=
NULL
;
self
->
pers_func
=
NULL
;
...
@@ -6669,30 +6658,19 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_i
...
@@ -6669,30 +6658,19 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_i
self
->
stack
=
(
Pdata
*
)
Pdata_New
();
self
->
stack
=
(
Pdata
*
)
Pdata_New
();
if
(
self
->
stack
==
NULL
)
if
(
self
->
stack
==
NULL
)
return
NULL
;
return
1
;
self
->
memo_size
=
32
;
self
->
memo_size
=
32
;
self
->
memo
=
_Unpickler_NewMemo
(
self
->
memo_size
);
self
->
memo
=
_Unpickler_NewMemo
(
self
->
memo_size
);
if
(
self
->
memo
==
NULL
)
if
(
self
->
memo
==
NULL
)
return
NULL
;
return
-
1
;
self
->
proto
=
0
;
self
->
proto
=
0
;
Py_RETURN_NONE
;
}
/* Wrap the Clinic generated signature to slot it in tp_init. */
static
int
Unpickler_init
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
PyObject
*
result
=
_pickle_Unpickler___init__
(
self
,
args
,
kwargs
);
if
(
result
==
NULL
)
{
return
-
1
;
}
Py_DECREF
(
result
);
return
0
;
return
0
;
}
}
/* Define a proxy object for the Unpickler's internal memo object. This is to
/* Define a proxy object for the Unpickler's internal memo object. This is to
* avoid breaking code like:
* avoid breaking code like:
* unpickler.memo.clear()
* unpickler.memo.clear()
...
@@ -7096,7 +7074,7 @@ static PyTypeObject Unpickler_Type = {
...
@@ -7096,7 +7074,7 @@ static PyTypeObject Unpickler_Type = {
0
,
/*tp_descr_get*/
0
,
/*tp_descr_get*/
0
,
/*tp_descr_set*/
0
,
/*tp_descr_set*/
0
,
/*tp_dictoffset*/
0
,
/*tp_dictoffset*/
Unpickler_init
,
/*tp_init*/
_pickle_Unpickler___init__
,
/*tp_init*/
PyType_GenericAlloc
,
/*tp_alloc*/
PyType_GenericAlloc
,
/*tp_alloc*/
PyType_GenericNew
,
/*tp_new*/
PyType_GenericNew
,
/*tp_new*/
PyObject_GC_Del
,
/*tp_free*/
PyObject_GC_Del
,
/*tp_free*/
...
...
Python/getargs.c
Dosyayı görüntüle @
b7ccb204
...
@@ -1805,7 +1805,7 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
...
@@ -1805,7 +1805,7 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
/* For type constructors that don't take keyword args
/* For type constructors that don't take keyword args
*
*
* Sets a TypeError and returns 0 if the
kwds dict
is
* Sets a TypeError and returns 0 if the
args/kwargs
is
* not empty, returns 1 otherwise
* not empty, returns 1 otherwise
*/
*/
int
int
...
@@ -1824,6 +1824,25 @@ _PyArg_NoKeywords(const char *funcname, PyObject *kw)
...
@@ -1824,6 +1824,25 @@ _PyArg_NoKeywords(const char *funcname, PyObject *kw)
funcname
);
funcname
);
return
0
;
return
0
;
}
}
int
_PyArg_NoPositional
(
const
char
*
funcname
,
PyObject
*
args
)
{
if
(
args
==
NULL
)
return
1
;
if
(
!
PyTuple_CheckExact
(
args
))
{
PyErr_BadInternalCall
();
return
0
;
}
if
(
PyTuple_GET_SIZE
(
args
)
==
0
)
return
1
;
PyErr_Format
(
PyExc_TypeError
,
"%s does not take positional arguments"
,
funcname
);
return
0
;
}
#ifdef __cplusplus
#ifdef __cplusplus
};
};
#endif
#endif
Tools/clinic/clinic.py
Dosyayı görüntüle @
b7ccb204
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment