1.. highlight:: c 2 3.. _new-types-topics: 4 5***************************************** 6Defining Extension Types: Assorted Topics 7***************************************** 8 9.. _dnt-type-methods: 10 11This section aims to give a quick fly-by on the various type methods you can 12implement and what they do. 13 14Here is the definition of :c:type:`PyTypeObject`, with some fields only used in 15:ref:`debug builds <debug-build>` omitted: 16 17.. literalinclude:: ../includes/typestruct.h 18 19 20Now that's a *lot* of methods. Don't worry too much though -- if you have 21a type you want to define, the chances are very good that you will only 22implement a handful of these. 23 24As you probably expect by now, we're going to go over this and give more 25information about the various handlers. We won't go in the order they are 26defined in the structure, because there is a lot of historical baggage that 27impacts the ordering of the fields. It's often easiest to find an example 28that includes the fields you need and then change the values to suit your new 29type. :: 30 31 const char *tp_name; /* For printing */ 32 33The name of the type -- as mentioned in the previous chapter, this will appear in 34various places, almost entirely for diagnostic purposes. Try to choose something 35that will be helpful in such a situation! :: 36 37 Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ 38 39These fields tell the runtime how much memory to allocate when new objects of 40this type are created. Python has some built-in support for variable length 41structures (think: strings, tuples) which is where the :c:member:`~PyTypeObject.tp_itemsize` field 42comes in. This will be dealt with later. :: 43 44 const char *tp_doc; 45 46Here you can put a string (or its address) that you want returned when the 47Python script references ``obj.__doc__`` to retrieve the doc string. 48 49Now we come to the basic type methods -- the ones most extension types will 50implement. 51 52 53Finalization and De-allocation 54------------------------------ 55 56.. index:: 57 single: object; deallocation 58 single: deallocation, object 59 single: object; finalization 60 single: finalization, of objects 61 62:: 63 64 destructor tp_dealloc; 65 66This function is called when the reference count of the instance of your type is 67reduced to zero and the Python interpreter wants to reclaim it. If your type 68has memory to free or other clean-up to perform, you can put it here. The 69object itself needs to be freed here as well. Here is an example of this 70function:: 71 72 static void 73 newdatatype_dealloc(newdatatypeobject *obj) 74 { 75 free(obj->obj_UnderlyingDatatypePtr); 76 Py_TYPE(obj)->tp_free((PyObject *)obj); 77 } 78 79If your type supports garbage collection, the destructor should call 80:c:func:`PyObject_GC_UnTrack` before clearing any member fields:: 81 82 static void 83 newdatatype_dealloc(newdatatypeobject *obj) 84 { 85 PyObject_GC_UnTrack(obj); 86 Py_CLEAR(obj->other_obj); 87 ... 88 Py_TYPE(obj)->tp_free((PyObject *)obj); 89 } 90 91.. index:: 92 single: PyErr_Fetch() 93 single: PyErr_Restore() 94 95One important requirement of the deallocator function is that it leaves any 96pending exceptions alone. This is important since deallocators are frequently 97called as the interpreter unwinds the Python stack; when the stack is unwound 98due to an exception (rather than normal returns), nothing is done to protect the 99deallocators from seeing that an exception has already been set. Any actions 100which a deallocator performs which may cause additional Python code to be 101executed may detect that an exception has been set. This can lead to misleading 102errors from the interpreter. The proper way to protect against this is to save 103a pending exception before performing the unsafe action, and restoring it when 104done. This can be done using the :c:func:`PyErr_Fetch` and 105:c:func:`PyErr_Restore` functions:: 106 107 static void 108 my_dealloc(PyObject *obj) 109 { 110 MyObject *self = (MyObject *) obj; 111 PyObject *cbresult; 112 113 if (self->my_callback != NULL) { 114 PyObject *err_type, *err_value, *err_traceback; 115 116 /* This saves the current exception state */ 117 PyErr_Fetch(&err_type, &err_value, &err_traceback); 118 119 cbresult = PyObject_CallNoArgs(self->my_callback); 120 if (cbresult == NULL) 121 PyErr_WriteUnraisable(self->my_callback); 122 else 123 Py_DECREF(cbresult); 124 125 /* This restores the saved exception state */ 126 PyErr_Restore(err_type, err_value, err_traceback); 127 128 Py_DECREF(self->my_callback); 129 } 130 Py_TYPE(obj)->tp_free((PyObject*)self); 131 } 132 133.. note:: 134 There are limitations to what you can safely do in a deallocator function. 135 First, if your type supports garbage collection (using :c:member:`~PyTypeObject.tp_traverse` 136 and/or :c:member:`~PyTypeObject.tp_clear`), some of the object's members can have been 137 cleared or finalized by the time :c:member:`~PyTypeObject.tp_dealloc` is called. Second, in 138 :c:member:`~PyTypeObject.tp_dealloc`, your object is in an unstable state: its reference 139 count is equal to zero. Any call to a non-trivial object or API (as in the 140 example above) might end up calling :c:member:`~PyTypeObject.tp_dealloc` again, causing a 141 double free and a crash. 142 143 Starting with Python 3.4, it is recommended not to put any complex 144 finalization code in :c:member:`~PyTypeObject.tp_dealloc`, and instead use the new 145 :c:member:`~PyTypeObject.tp_finalize` type method. 146 147 .. seealso:: 148 :pep:`442` explains the new finalization scheme. 149 150.. index:: 151 single: string; object representation 152 builtin: repr 153 154Object Presentation 155------------------- 156 157In Python, there are two ways to generate a textual representation of an object: 158the :func:`repr` function, and the :func:`str` function. (The :func:`print` 159function just calls :func:`str`.) These handlers are both optional. 160 161:: 162 163 reprfunc tp_repr; 164 reprfunc tp_str; 165 166The :c:member:`~PyTypeObject.tp_repr` handler should return a string object containing a 167representation of the instance for which it is called. Here is a simple 168example:: 169 170 static PyObject * 171 newdatatype_repr(newdatatypeobject * obj) 172 { 173 return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:%d}}", 174 obj->obj_UnderlyingDatatypePtr->size); 175 } 176 177If no :c:member:`~PyTypeObject.tp_repr` handler is specified, the interpreter will supply a 178representation that uses the type's :c:member:`~PyTypeObject.tp_name` and a uniquely-identifying 179value for the object. 180 181The :c:member:`~PyTypeObject.tp_str` handler is to :func:`str` what the :c:member:`~PyTypeObject.tp_repr` handler 182described above is to :func:`repr`; that is, it is called when Python code calls 183:func:`str` on an instance of your object. Its implementation is very similar 184to the :c:member:`~PyTypeObject.tp_repr` function, but the resulting string is intended for human 185consumption. If :c:member:`~PyTypeObject.tp_str` is not specified, the :c:member:`~PyTypeObject.tp_repr` handler is 186used instead. 187 188Here is a simple example:: 189 190 static PyObject * 191 newdatatype_str(newdatatypeobject * obj) 192 { 193 return PyUnicode_FromFormat("Stringified_newdatatype{{size:%d}}", 194 obj->obj_UnderlyingDatatypePtr->size); 195 } 196 197 198 199Attribute Management 200-------------------- 201 202For every object which can support attributes, the corresponding type must 203provide the functions that control how the attributes are resolved. There needs 204to be a function which can retrieve attributes (if any are defined), and another 205to set attributes (if setting attributes is allowed). Removing an attribute is 206a special case, for which the new value passed to the handler is ``NULL``. 207 208Python supports two pairs of attribute handlers; a type that supports attributes 209only needs to implement the functions for one pair. The difference is that one 210pair takes the name of the attribute as a :c:type:`char\*`, while the other 211accepts a :c:type:`PyObject\*`. Each type can use whichever pair makes more 212sense for the implementation's convenience. :: 213 214 getattrfunc tp_getattr; /* char * version */ 215 setattrfunc tp_setattr; 216 /* ... */ 217 getattrofunc tp_getattro; /* PyObject * version */ 218 setattrofunc tp_setattro; 219 220If accessing attributes of an object is always a simple operation (this will be 221explained shortly), there are generic implementations which can be used to 222provide the :c:type:`PyObject\*` version of the attribute management functions. 223The actual need for type-specific attribute handlers almost completely 224disappeared starting with Python 2.2, though there are many examples which have 225not been updated to use some of the new generic mechanism that is available. 226 227 228.. _generic-attribute-management: 229 230Generic Attribute Management 231^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 232 233Most extension types only use *simple* attributes. So, what makes the 234attributes simple? There are only a couple of conditions that must be met: 235 236#. The name of the attributes must be known when :c:func:`PyType_Ready` is 237 called. 238 239#. No special processing is needed to record that an attribute was looked up or 240 set, nor do actions need to be taken based on the value. 241 242Note that this list does not place any restrictions on the values of the 243attributes, when the values are computed, or how relevant data is stored. 244 245When :c:func:`PyType_Ready` is called, it uses three tables referenced by the 246type object to create :term:`descriptor`\s which are placed in the dictionary of the 247type object. Each descriptor controls access to one attribute of the instance 248object. Each of the tables is optional; if all three are ``NULL``, instances of 249the type will only have attributes that are inherited from their base type, and 250should leave the :c:member:`~PyTypeObject.tp_getattro` and :c:member:`~PyTypeObject.tp_setattro` fields ``NULL`` as 251well, allowing the base type to handle attributes. 252 253The tables are declared as three fields of the type object:: 254 255 struct PyMethodDef *tp_methods; 256 struct PyMemberDef *tp_members; 257 struct PyGetSetDef *tp_getset; 258 259If :c:member:`~PyTypeObject.tp_methods` is not ``NULL``, it must refer to an array of 260:c:type:`PyMethodDef` structures. Each entry in the table is an instance of this 261structure:: 262 263 typedef struct PyMethodDef { 264 const char *ml_name; /* method name */ 265 PyCFunction ml_meth; /* implementation function */ 266 int ml_flags; /* flags */ 267 const char *ml_doc; /* docstring */ 268 } PyMethodDef; 269 270One entry should be defined for each method provided by the type; no entries are 271needed for methods inherited from a base type. One additional entry is needed 272at the end; it is a sentinel that marks the end of the array. The 273:attr:`ml_name` field of the sentinel must be ``NULL``. 274 275The second table is used to define attributes which map directly to data stored 276in the instance. A variety of primitive C types are supported, and access may 277be read-only or read-write. The structures in the table are defined as:: 278 279 typedef struct PyMemberDef { 280 const char *name; 281 int type; 282 int offset; 283 int flags; 284 const char *doc; 285 } PyMemberDef; 286 287For each entry in the table, a :term:`descriptor` will be constructed and added to the 288type which will be able to extract a value from the instance structure. The 289:attr:`type` field should contain one of the type codes defined in the 290:file:`structmember.h` header; the value will be used to determine how to 291convert Python values to and from C values. The :attr:`flags` field is used to 292store flags which control how the attribute can be accessed. 293 294The following flag constants are defined in :file:`structmember.h`; they may be 295combined using bitwise-OR. 296 297+---------------------------+----------------------------------------------+ 298| Constant | Meaning | 299+===========================+==============================================+ 300| :const:`READONLY` | Never writable. | 301+---------------------------+----------------------------------------------+ 302| :const:`PY_AUDIT_READ` | Emit an ``object.__getattr__`` | 303| | :ref:`audit events <audit-events>` before | 304| | reading. | 305+---------------------------+----------------------------------------------+ 306 307.. versionchanged:: 3.10 308 :const:`RESTRICTED`, :const:`READ_RESTRICTED` and :const:`WRITE_RESTRICTED` 309 are deprecated. However, :const:`READ_RESTRICTED` is an alias for 310 :const:`PY_AUDIT_READ`, so fields that specify either :const:`RESTRICTED` 311 or :const:`READ_RESTRICTED` will also raise an audit event. 312 313.. index:: 314 single: READONLY 315 single: READ_RESTRICTED 316 single: WRITE_RESTRICTED 317 single: RESTRICTED 318 single: PY_AUDIT_READ 319 320An interesting advantage of using the :c:member:`~PyTypeObject.tp_members` table to build 321descriptors that are used at runtime is that any attribute defined this way can 322have an associated doc string simply by providing the text in the table. An 323application can use the introspection API to retrieve the descriptor from the 324class object, and get the doc string using its :attr:`__doc__` attribute. 325 326As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :attr:`name` value 327of ``NULL`` is required. 328 329.. XXX Descriptors need to be explained in more detail somewhere, but not here. 330 331 Descriptor objects have two handler functions which correspond to the 332 \member{tp_getattro} and \member{tp_setattro} handlers. The 333 \method{__get__()} handler is a function which is passed the descriptor, 334 instance, and type objects, and returns the value of the attribute, or it 335 returns \NULL{} and sets an exception. The \method{__set__()} handler is 336 passed the descriptor, instance, type, and new value; 337 338 339Type-specific Attribute Management 340^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 341 342For simplicity, only the :c:type:`char\*` version will be demonstrated here; the 343type of the name parameter is the only difference between the :c:type:`char\*` 344and :c:type:`PyObject\*` flavors of the interface. This example effectively does 345the same thing as the generic example above, but does not use the generic 346support added in Python 2.2. It explains how the handler functions are 347called, so that if you do need to extend their functionality, you'll understand 348what needs to be done. 349 350The :c:member:`~PyTypeObject.tp_getattr` handler is called when the object requires an attribute 351look-up. It is called in the same situations where the :meth:`__getattr__` 352method of a class would be called. 353 354Here is an example:: 355 356 static PyObject * 357 newdatatype_getattr(newdatatypeobject *obj, char *name) 358 { 359 if (strcmp(name, "data") == 0) 360 { 361 return PyLong_FromLong(obj->data); 362 } 363 364 PyErr_Format(PyExc_AttributeError, 365 "'%.50s' object has no attribute '%.400s'", 366 tp->tp_name, name); 367 return NULL; 368 } 369 370The :c:member:`~PyTypeObject.tp_setattr` handler is called when the :meth:`__setattr__` or 371:meth:`__delattr__` method of a class instance would be called. When an 372attribute should be deleted, the third parameter will be ``NULL``. Here is an 373example that simply raises an exception; if this were really all you wanted, the 374:c:member:`~PyTypeObject.tp_setattr` handler should be set to ``NULL``. :: 375 376 static int 377 newdatatype_setattr(newdatatypeobject *obj, char *name, PyObject *v) 378 { 379 PyErr_Format(PyExc_RuntimeError, "Read-only attribute: %s", name); 380 return -1; 381 } 382 383Object Comparison 384----------------- 385 386:: 387 388 richcmpfunc tp_richcompare; 389 390The :c:member:`~PyTypeObject.tp_richcompare` handler is called when comparisons are needed. It is 391analogous to the :ref:`rich comparison methods <richcmpfuncs>`, like 392:meth:`__lt__`, and also called by :c:func:`PyObject_RichCompare` and 393:c:func:`PyObject_RichCompareBool`. 394 395This function is called with two Python objects and the operator as arguments, 396where the operator is one of ``Py_EQ``, ``Py_NE``, ``Py_LE``, ``Py_GE``, 397``Py_LT`` or ``Py_GT``. It should compare the two objects with respect to the 398specified operator and return ``Py_True`` or ``Py_False`` if the comparison is 399successful, ``Py_NotImplemented`` to indicate that comparison is not 400implemented and the other object's comparison method should be tried, or ``NULL`` 401if an exception was set. 402 403Here is a sample implementation, for a datatype that is considered equal if the 404size of an internal pointer is equal:: 405 406 static PyObject * 407 newdatatype_richcmp(PyObject *obj1, PyObject *obj2, int op) 408 { 409 PyObject *result; 410 int c, size1, size2; 411 412 /* code to make sure that both arguments are of type 413 newdatatype omitted */ 414 415 size1 = obj1->obj_UnderlyingDatatypePtr->size; 416 size2 = obj2->obj_UnderlyingDatatypePtr->size; 417 418 switch (op) { 419 case Py_LT: c = size1 < size2; break; 420 case Py_LE: c = size1 <= size2; break; 421 case Py_EQ: c = size1 == size2; break; 422 case Py_NE: c = size1 != size2; break; 423 case Py_GT: c = size1 > size2; break; 424 case Py_GE: c = size1 >= size2; break; 425 } 426 result = c ? Py_True : Py_False; 427 Py_INCREF(result); 428 return result; 429 } 430 431 432Abstract Protocol Support 433------------------------- 434 435Python supports a variety of *abstract* 'protocols;' the specific interfaces 436provided to use these interfaces are documented in :ref:`abstract`. 437 438 439A number of these abstract interfaces were defined early in the development of 440the Python implementation. In particular, the number, mapping, and sequence 441protocols have been part of Python since the beginning. Other protocols have 442been added over time. For protocols which depend on several handler routines 443from the type implementation, the older protocols have been defined as optional 444blocks of handlers referenced by the type object. For newer protocols there are 445additional slots in the main type object, with a flag bit being set to indicate 446that the slots are present and should be checked by the interpreter. (The flag 447bit does not indicate that the slot values are non-``NULL``. The flag may be set 448to indicate the presence of a slot, but a slot may still be unfilled.) :: 449 450 PyNumberMethods *tp_as_number; 451 PySequenceMethods *tp_as_sequence; 452 PyMappingMethods *tp_as_mapping; 453 454If you wish your object to be able to act like a number, a sequence, or a 455mapping object, then you place the address of a structure that implements the C 456type :c:type:`PyNumberMethods`, :c:type:`PySequenceMethods`, or 457:c:type:`PyMappingMethods`, respectively. It is up to you to fill in this 458structure with appropriate values. You can find examples of the use of each of 459these in the :file:`Objects` directory of the Python source distribution. :: 460 461 hashfunc tp_hash; 462 463This function, if you choose to provide it, should return a hash number for an 464instance of your data type. Here is a simple example:: 465 466 static Py_hash_t 467 newdatatype_hash(newdatatypeobject *obj) 468 { 469 Py_hash_t result; 470 result = obj->some_size + 32767 * obj->some_number; 471 if (result == -1) 472 result = -2; 473 return result; 474 } 475 476:c:type:`Py_hash_t` is a signed integer type with a platform-varying width. 477Returning ``-1`` from :c:member:`~PyTypeObject.tp_hash` indicates an error, 478which is why you should be careful to avoid returning it when hash computation 479is successful, as seen above. 480 481:: 482 483 ternaryfunc tp_call; 484 485This function is called when an instance of your data type is "called", for 486example, if ``obj1`` is an instance of your data type and the Python script 487contains ``obj1('hello')``, the :c:member:`~PyTypeObject.tp_call` handler is invoked. 488 489This function takes three arguments: 490 491#. *self* is the instance of the data type which is the subject of the call. 492 If the call is ``obj1('hello')``, then *self* is ``obj1``. 493 494#. *args* is a tuple containing the arguments to the call. You can use 495 :c:func:`PyArg_ParseTuple` to extract the arguments. 496 497#. *kwds* is a dictionary of keyword arguments that were passed. If this is 498 non-``NULL`` and you support keyword arguments, use 499 :c:func:`PyArg_ParseTupleAndKeywords` to extract the arguments. If you 500 do not want to support keyword arguments and this is non-``NULL``, raise a 501 :exc:`TypeError` with a message saying that keyword arguments are not supported. 502 503Here is a toy ``tp_call`` implementation:: 504 505 static PyObject * 506 newdatatype_call(newdatatypeobject *self, PyObject *args, PyObject *kwds) 507 { 508 PyObject *result; 509 const char *arg1; 510 const char *arg2; 511 const char *arg3; 512 513 if (!PyArg_ParseTuple(args, "sss:call", &arg1, &arg2, &arg3)) { 514 return NULL; 515 } 516 result = PyUnicode_FromFormat( 517 "Returning -- value: [%d] arg1: [%s] arg2: [%s] arg3: [%s]\n", 518 obj->obj_UnderlyingDatatypePtr->size, 519 arg1, arg2, arg3); 520 return result; 521 } 522 523:: 524 525 /* Iterators */ 526 getiterfunc tp_iter; 527 iternextfunc tp_iternext; 528 529These functions provide support for the iterator protocol. Both handlers 530take exactly one parameter, the instance for which they are being called, 531and return a new reference. In the case of an error, they should set an 532exception and return ``NULL``. :c:member:`~PyTypeObject.tp_iter` corresponds 533to the Python :meth:`__iter__` method, while :c:member:`~PyTypeObject.tp_iternext` 534corresponds to the Python :meth:`~iterator.__next__` method. 535 536Any :term:`iterable` object must implement the :c:member:`~PyTypeObject.tp_iter` 537handler, which must return an :term:`iterator` object. Here the same guidelines 538apply as for Python classes: 539 540* For collections (such as lists and tuples) which can support multiple 541 independent iterators, a new iterator should be created and returned by 542 each call to :c:member:`~PyTypeObject.tp_iter`. 543* Objects which can only be iterated over once (usually due to side effects of 544 iteration, such as file objects) can implement :c:member:`~PyTypeObject.tp_iter` 545 by returning a new reference to themselves -- and should also therefore 546 implement the :c:member:`~PyTypeObject.tp_iternext` handler. 547 548Any :term:`iterator` object should implement both :c:member:`~PyTypeObject.tp_iter` 549and :c:member:`~PyTypeObject.tp_iternext`. An iterator's 550:c:member:`~PyTypeObject.tp_iter` handler should return a new reference 551to the iterator. Its :c:member:`~PyTypeObject.tp_iternext` handler should 552return a new reference to the next object in the iteration, if there is one. 553If the iteration has reached the end, :c:member:`~PyTypeObject.tp_iternext` 554may return ``NULL`` without setting an exception, or it may set 555:exc:`StopIteration` *in addition* to returning ``NULL``; avoiding 556the exception can yield slightly better performance. If an actual error 557occurs, :c:member:`~PyTypeObject.tp_iternext` should always set an exception 558and return ``NULL``. 559 560 561.. _weakref-support: 562 563Weak Reference Support 564---------------------- 565 566One of the goals of Python's weak reference implementation is to allow any type 567to participate in the weak reference mechanism without incurring the overhead on 568performance-critical objects (such as numbers). 569 570.. seealso:: 571 Documentation for the :mod:`weakref` module. 572 573For an object to be weakly referencable, the extension type must do two things: 574 575#. Include a :c:type:`PyObject\*` field in the C object structure dedicated to 576 the weak reference mechanism. The object's constructor should leave it 577 ``NULL`` (which is automatic when using the default 578 :c:member:`~PyTypeObject.tp_alloc`). 579 580#. Set the :c:member:`~PyTypeObject.tp_weaklistoffset` type member 581 to the offset of the aforementioned field in the C object structure, 582 so that the interpreter knows how to access and modify that field. 583 584Concretely, here is how a trivial object structure would be augmented 585with the required field:: 586 587 typedef struct { 588 PyObject_HEAD 589 PyObject *weakreflist; /* List of weak references */ 590 } TrivialObject; 591 592And the corresponding member in the statically-declared type object:: 593 594 static PyTypeObject TrivialType = { 595 PyVarObject_HEAD_INIT(NULL, 0) 596 /* ... other members omitted for brevity ... */ 597 .tp_weaklistoffset = offsetof(TrivialObject, weakreflist), 598 }; 599 600The only further addition is that ``tp_dealloc`` needs to clear any weak 601references (by calling :c:func:`PyObject_ClearWeakRefs`) if the field is 602non-``NULL``:: 603 604 static void 605 Trivial_dealloc(TrivialObject *self) 606 { 607 /* Clear weakrefs first before calling any destructors */ 608 if (self->weakreflist != NULL) 609 PyObject_ClearWeakRefs((PyObject *) self); 610 /* ... remainder of destruction code omitted for brevity ... */ 611 Py_TYPE(self)->tp_free((PyObject *) self); 612 } 613 614 615More Suggestions 616---------------- 617 618In order to learn how to implement any specific method for your new data type, 619get the :term:`CPython` source code. Go to the :file:`Objects` directory, 620then search the C source files for ``tp_`` plus the function you want 621(for example, ``tp_richcompare``). You will find examples of the function 622you want to implement. 623 624When you need to verify that an object is a concrete instance of the type you 625are implementing, use the :c:func:`PyObject_TypeCheck` function. A sample of 626its use might be something like the following:: 627 628 if (!PyObject_TypeCheck(some_object, &MyType)) { 629 PyErr_SetString(PyExc_TypeError, "arg #1 not a mything"); 630 return NULL; 631 } 632 633.. seealso:: 634 Download CPython source releases. 635 https://www.python.org/downloads/source/ 636 637 The CPython project on GitHub, where the CPython source code is developed. 638 https://github.com/python/cpython 639