2019-05-17 06:55:34 -03:00
|
|
|
.. highlight:: c
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _concrete:
|
|
|
|
|
|
|
|
**********************
|
|
|
|
Concrete Objects Layer
|
|
|
|
**********************
|
|
|
|
|
|
|
|
The functions in this chapter are specific to certain Python object types.
|
|
|
|
Passing them an object of the wrong type is not a good idea; if you receive an
|
|
|
|
object from a Python program and you are not sure that it has the right type,
|
|
|
|
you must perform a type check first; for example, to check that an object is a
|
2010-10-06 07:11:56 -03:00
|
|
|
dictionary, use :c:func:`PyDict_Check`. The chapter is structured like the
|
2007-08-15 11:28:22 -03:00
|
|
|
"family tree" of Python object types.
|
|
|
|
|
|
|
|
.. warning::
|
|
|
|
|
|
|
|
While the functions described in this chapter carefully check the type of the
|
2019-10-30 07:03:20 -03:00
|
|
|
objects which are passed in, many of them do not check for ``NULL`` being passed
|
|
|
|
instead of a valid object. Allowing ``NULL`` to be passed in can cause memory
|
2007-08-15 11:28:22 -03:00
|
|
|
access violations and immediate termination of the interpreter.
|
|
|
|
|
|
|
|
|
|
|
|
.. _fundamental:
|
|
|
|
|
|
|
|
Fundamental Objects
|
|
|
|
===================
|
|
|
|
|
|
|
|
This section describes Python type objects and the singleton object ``None``.
|
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
.. toctree::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
type.rst
|
|
|
|
none.rst
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _numericobjects:
|
|
|
|
|
|
|
|
Numeric Objects
|
|
|
|
===============
|
|
|
|
|
|
|
|
.. index:: object: numeric
|
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
.. toctree::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
long.rst
|
|
|
|
bool.rst
|
|
|
|
float.rst
|
|
|
|
complex.rst
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. _sequenceobjects:
|
|
|
|
|
|
|
|
Sequence Objects
|
|
|
|
================
|
|
|
|
|
|
|
|
.. index:: object: sequence
|
|
|
|
|
|
|
|
Generic operations on sequence objects were discussed in the previous chapter;
|
|
|
|
this section deals with the specific kinds of sequence objects that are
|
|
|
|
intrinsic to the Python language.
|
|
|
|
|
2008-01-05 17:16:33 -04:00
|
|
|
.. XXX sort out unicode, str, bytes and bytearray
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
.. toctree::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-05-26 12:01:55 -03:00
|
|
|
bytes.rst
|
2008-05-26 13:04:49 -03:00
|
|
|
bytearray.rst
|
2008-01-20 05:30:57 -04:00
|
|
|
unicode.rst
|
|
|
|
tuple.rst
|
|
|
|
list.rst
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
.. _mapobjects:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-11-07 17:05:48 -04:00
|
|
|
Container Objects
|
|
|
|
=================
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
.. index:: object: mapping
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
.. toctree::
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
dict.rst
|
2013-11-07 17:05:48 -04:00
|
|
|
set.rst
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
.. _otherobjects:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-11-07 17:05:48 -04:00
|
|
|
Function Objects
|
|
|
|
================
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
.. toctree::
|
|
|
|
|
|
|
|
function.rst
|
|
|
|
method.rst
|
2013-11-07 17:05:48 -04:00
|
|
|
cell.rst
|
|
|
|
code.rst
|
|
|
|
|
|
|
|
|
|
|
|
Other Objects
|
|
|
|
=============
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
|
2008-01-20 05:30:57 -04:00
|
|
|
file.rst
|
|
|
|
module.rst
|
|
|
|
iterator.rst
|
|
|
|
descriptor.rst
|
|
|
|
slice.rst
|
2010-09-28 20:59:51 -03:00
|
|
|
memoryview.rst
|
2008-01-20 05:30:57 -04:00
|
|
|
weakref.rst
|
2009-05-05 19:31:58 -03:00
|
|
|
capsule.rst
|
2008-01-20 05:30:57 -04:00
|
|
|
gen.rst
|
Issue #24400: Introduce a distinct type for 'async def' coroutines.
Summary of changes:
1. Coroutines now have a distinct, separate from generators
type at the C level: PyGen_Type, and a new typedef PyCoroObject.
PyCoroObject shares the initial segment of struct layout with
PyGenObject, making it possible to reuse existing generators
machinery. The new type is exposed as 'types.CoroutineType'.
As a consequence of having a new type, CO_GENERATOR flag is
no longer applied to coroutines.
2. Having a separate type for coroutines made it possible to add
an __await__ method to the type. Although it is not used by the
interpreter (see details on that below), it makes coroutines
naturally (without using __instancecheck__) conform to
collections.abc.Coroutine and collections.abc.Awaitable ABCs.
[The __instancecheck__ is still used for generator-based
coroutines, as we don't want to add __await__ for generators.]
3. Add new opcode: GET_YIELD_FROM_ITER. The opcode is needed to
allow passing native coroutines to the YIELD_FROM opcode.
Before this change, 'yield from o' expression was compiled to:
(o)
GET_ITER
LOAD_CONST
YIELD_FROM
Now, we use GET_YIELD_FROM_ITER instead of GET_ITER.
The reason for adding a new opcode is that GET_ITER is used
in some contexts (such as 'for .. in' loops) where passing
a coroutine object is invalid.
4. Add two new introspection functions to the inspec module:
getcoroutinestate(c) and getcoroutinelocals(c).
5. inspect.iscoroutine(o) is updated to test if 'o' is a native
coroutine object. Before this commit it used abc.Coroutine,
and it was requested to update inspect.isgenerator(o) to use
abc.Generator; it was decided, however, that inspect functions
should really be tailored for checking for native types.
6. sys.set_coroutine_wrapper(w) API is updated to work with only
native coroutines. Since types.coroutine decorator supports
any type of callables now, it would be confusing that it does
not work for all types of coroutines.
7. Exceptions logic in generators C implementation was updated
to raise clearer messages for coroutines:
Before: TypeError("generator raised StopIteration")
After: TypeError("coroutine raised StopIteration")
2015-06-22 13:19:30 -03:00
|
|
|
coro.rst
|
2018-05-22 14:31:56 -03:00
|
|
|
contextvars.rst
|
2008-01-20 05:30:57 -04:00
|
|
|
datetime.rst
|
2020-08-10 11:32:21 -03:00
|
|
|
decimal.rst
|