chunk_id large_stringlengths 36 36 | doc_type large_stringclasses 2
values | category large_stringclasses 17
values | document large_stringclasses 50
values | version_raw large_stringclasses 590
values | chunk_index int64 0 262 | text large_stringlengths 11 5.69k | file_path large_stringclasses 882
values |
|---|---|---|---|---|---|---|---|
d613fbe1-773d-5944-8d02-9b3e3f52f4f7 | docs | python | python_datamodel | 313 | 128 | When a new class is created by `type.__new__`, the object provided as the
namespace parameter is copied to a new ordered mapping and the original
object is discarded. The new copy is wrapped in a read-only proxy, which
becomes the [`__dict__`](#type.__dict__ "type.__dict__") attribute of the class object.
See also
[*... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
ce390eef-9782-504d-aaea-45da4401e0c6 | docs | python | python_datamodel | 313 | 129 | [`isinstance()`](../library/functions.html#isinstance "isinstance") and [`issubclass()`](../library/functions.html#issubclass "issubclass") built-in functions.
In particular, the metaclass [`abc.ABCMeta`](../library/abc.html#abc.ABCMeta "abc.ABCMeta") implements these methods in
order to allow the addition of Abstract... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
854d8a32-d178-591c-80d7-ba88b96a4c10 | docs | python | python_datamodel | 313 | 130 | Note that these methods are looked up on the type (metaclass) of a class. They
cannot be defined as class methods in the actual class. This is consistent with
the lookup of special methods that are called on instances, only in this
case the instance is itself a class.
See also
[**PEP 3119**](https://peps.python.org/p... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
9f4820a4-cc95-5393-a949-c5eaeb57a2b8 | docs | python | python_datamodel | 313 | 131 | ### 3.3.5. Emulating generic types[¶](#emulating-generic-types "Link to this heading")
When using [type annotations](../glossary.html#term-annotation), it is often useful to
*parameterize* a [generic type](../glossary.html#term-generic-type) using Python’s square-brackets notation.
For example, the annotation `list[in... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
ae809cd7-e268-5dc4-a156-a48955566a61 | docs | python | python_datamodel | 313 | 132 | parameterized at runtime and understood by static type-checkers.
A class can *generally* only be parameterized if it defines the special
class method `__class_getitem__()`.
*classmethod* object.\_\_class\_getitem\_\_(*cls*, *key*)[¶](#object.__class_getitem__ "Link to this definition")
: Return an object repres... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
2d83a780-2bbd-5086-af57-846b4f054898 | docs | python | python_datamodel | 313 | 133 | To implement custom generic classes that can be parameterized at runtime and
understood by static type-checkers, users should either inherit from a standard
library class that already implements [`__class_getitem__()`](#object.__class_getitem__ "object.__class_getitem__"), or
inherit from [`typing.Generic`](../library/... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
e0fedc36-87b6-59b7-8bba-2a8eec322cba | docs | python | python_datamodel | 313 | 134 | brackets will call the [`__getitem__()`](#object.__getitem__ "object.__getitem__") instance method defined on
the object’s class. However, if the object being subscribed is itself a class,
the class method [`__class_getitem__()`](#object.__class_getitem__ "object.__class_getitem__") may be called instead.
`__class_geti... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
bf8eaf58-f8b2-5d5a-a42f-f690863b998b | docs | python | python_datamodel | 313 | 135 | if hasattr(class_of_obj, '__getitem__'):
return class_of_obj.__getitem__(obj, x)
# Else, if obj is a class and defines __class_getitem__,
# call obj.__class_getitem__(x)
elif isclass(obj) and hasattr(obj, '__class_getitem__'):
return obj.__class_getitem__(x)
# Else, raise an except... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
f0ef7106-dda4-5d1b-ac3a-40a5874e2897 | docs | python | python_datamodel | 313 | 136 | ```None
>>> # list has class "type" as its metaclass, like most classes:
>>> type(list)
<class 'type'>
>>> type(dict) == type(list) == type(tuple) == type(str) == type(bytes)
True
>>> # "list[int]" calls "list.__class_getitem__(int)"
>>> list[int]
list[int]
>>> # list.__class_getitem__ returns a GenericAlias object:
>>... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
7396cf10-ec69-5f09-b10f-fb2bafd7059d | docs | python | python_datamodel | 313 | 137 | >>> # and the result is not a GenericAlias object:
>>> Menu['SPAM']
<Menu.SPAM: 'spam'>
>>> type(Menu['SPAM'])
<enum 'Menu'>
```
See also
[**PEP 560**](https://peps.python.org/pep-0560/) - Core Support for typing module and generic types
: Introducing [`__class_getitem__()`](#object.__class_getitem__ "object.__clas... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
86a861e3-87bd-593d-aed2-3d3c4c597769 | docs | python | python_datamodel | 313 | 138 | ### 3.3.7. Emulating container types[¶](#emulating-container-types "Link to this heading")
The following methods can be defined to implement container objects. None of them
are provided by the [`object`](../library/functions.html#object "object") class itself. Containers usually are
[sequences](../glossary.html#term-s... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
d247b623-dda2-57f7-aa40-23dc0957531d | docs | python | python_datamodel | 313 | 139 | `keys()`, `values()`, `items()`, `get()`, `clear()`,
`setdefault()`, `pop()`, `popitem()`, `copy()`, and
`update()` behaving similar to those for Python’s standard [`dictionary`](../library/stdtypes.html#dict "dict")
objects. The [`collections.abc`](../library/collections.abc.html#module-collections.abc "collections.ab... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
b2da6e61-edd3-5964-ba63-2a8919b54830 | docs | python | python_datamodel | 313 | 140 | [`append()`](../library/stdtypes.html#sequence.append "sequence.append"), [`clear()`](../library/stdtypes.html#sequence.clear "sequence.clear"), [`count()`](../library/stdtypes.html#sequence.count "sequence.count"),
[`extend()`](../library/stdtypes.html#sequence.extend "sequence.extend"), [`index()`](../library/stdtype... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
e76da707-e174-55d2-8287-87f933dbf572 | docs | python | python_datamodel | 313 | 141 | [`__mul__()`](#object.__mul__ "object.__mul__"), [`__rmul__()`](#object.__rmul__ "object.__rmul__") and [`__imul__()`](#object.__imul__ "object.__imul__")
described below; they should not define other numerical
operators.
It is recommended that both mappings and sequences implement the
[`__contains__()`](#object.__con... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
f04fb33b-f31a-5818-9502-239acfa89e42 | docs | python | python_datamodel | 313 | 142 | of the object, an integer `>=` 0. Also, an object that doesn’t define a
[`__bool__()`](#object.__bool__ "object.__bool__") method and whose `__len__()` method returns zero is
considered to be false in a Boolean context.
**CPython implementation detail:** In CPython, the length is required to be at most... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
57302ba9-1503-51be-aa25-de12cc77e59c | docs | python | python_datamodel | 313 | 143 | length for the object (which may be greater or less than the actual length).
The length must be an integer `>=` 0. The return value may also be
[`NotImplemented`](../library/constants.html#NotImplemented "NotImplemented"), which is treated the same as if the
`__length_hint__` method didn’t exist at all.... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
ad0266d9-af31-538f-9c18-66ca693c9d42 | docs | python | python_datamodel | 313 | 144 | [`slice`](../library/functions.html#slice "slice") objects as well. Negative index support is also optional.
If *key* is
of an inappropriate type, [`TypeError`](../library/exceptions.html#TypeError "TypeError") may be raised; if *key* is a value
outside the set of indexes for the sequence (after any spe... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
a297d681-f243-5690-a56f-48d7c1e4ae8a | docs | python | python_datamodel | 313 | 145 | class method [`__class_getitem__()`](#object.__class_getitem__ "object.__class_getitem__") may be called instead of
`__getitem__()`. See [\_\_class\_getitem\_\_ versus \_\_getitem\_\_](#classgetitem-versus-getitem) for more
details.
object.\_\_setitem\_\_(*self*, *key*, *value*)[¶](#object.__setitem__ "Lin... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
d6014d37-b964-5a11-b82d-52faf9dd5cbe | docs | python | python_datamodel | 313 | 146 | [`__getitem__()`](#object.__getitem__ "object.__getitem__"). This should only be implemented for mappings if the
objects support removal of keys, or for sequences if elements can be removed
from the sequence. The same exceptions should be raised for improper *key*
values as for the [`__getitem__()`](#ob... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
666ab8c1-18a5-53db-aa37-8bafbe8e912a | docs | python | python_datamodel | 313 | 147 | object.\_\_reversed\_\_(*self*)[¶](#object.__reversed__ "Link to this definition")
: Called (if present) by the [`reversed()`](../library/functions.html#reversed "reversed") built-in to implement
reverse iteration. It should return a new iterator object that iterates
over all the objects in the container in r... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
1fe79268-685d-5b91-971d-14288de89f3f | docs | python | python_datamodel | 313 | 148 | The membership test operators ([`in`](expressions.html#in) and [`not in`](expressions.html#not-in)) are normally
implemented as an iteration through a container. However, container objects can
supply the following special method with a more efficient implementation, which
also does not require the object be iterable.
... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
983074b7-354e-5bdf-9123-7379de272714 | docs | python | python_datamodel | 313 | 149 | reference](expressions.html#membership-test-details).
### 3.3.8. Emulating numeric types[¶](#emulating-numeric-types "Link to this heading")
The following methods can be defined to emulate numeric objects. Methods
corresponding to operations that are not supported by the particular kind of
number implemented (e.g... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
bf9e931f-c37a-53c3-a957-4e0df533b2c7 | docs | python | python_datamodel | 313 | 150 | object.\_\_divmod\_\_(*self*, *other*)[¶](#object.__divmod__ "Link to this definition")
object.\_\_pow\_\_(*self*, *other*[, *modulo*])[¶](#object.__pow__ "Link to this definition")
object.\_\_lshift\_\_(*self*, *other*)[¶](#object.__lshift__ "Link to this definition")
object.\_\_rshift\_\_(*self*, *other*)[¶](#obje... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
7131848b-60bf-5d12-9b61-71dc839a5a57 | docs | python | python_datamodel | 313 | 151 | has an [`__add__()`](#object.__add__ "object.__add__") method, `type(x).__add__(x, y)` is called. The
[`__divmod__()`](#object.__divmod__ "object.__divmod__") method should be the equivalent to using
[`__floordiv__()`](#object.__floordiv__ "object.__floordiv__") and [`__mod__()`](#object.__mod__ "object.__m... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
b861d20d-4b57-520a-a76f-837d1079f87b | docs | python | python_datamodel | 313 | 152 | object.\_\_rmul\_\_(*self*, *other*)[¶](#object.__rmul__ "Link to this definition")
object.\_\_rmatmul\_\_(*self*, *other*)[¶](#object.__rmatmul__ "Link to this definition")
object.\_\_rtruediv\_\_(*self*, *other*)[¶](#object.__rtruediv__ "Link to this definition")
object.\_\_rfloordiv\_\_(*self*, *other*)[¶](#objec... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
3229e7b3-72f2-5c42-8bf9-481eb6dcc70b | docs | python | python_datamodel | 313 | 153 | object.\_\_ror\_\_(*self*, *other*)[¶](#object.__ror__ "Link to this definition")
: These methods are called to implement the binary arithmetic operations
(`+`, `-`, `*`, `@`, `/`, `//`, `%`, [`divmod()`](../library/functions.html#divmod "divmod"),
[`pow()`](../library/functions.html#pow "pow"), `**`, `<<`, `... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
fc80223f-e38e-5bda-a9c2-78d79636f0dd | docs | python | python_datamodel | 313 | 154 | coercion rules would become too complicated).
Note
If the right operand’s type is a subclass of the left operand’s type and
that subclass provides a different implementation of the reflected method
for the operation, this method will be called before the left operand’s
non-reflected method. Th... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
8c4a61b1-19f6-55c4-bd75-f65293d2f120 | docs | python | python_datamodel | 313 | 155 | object.\_\_ipow\_\_(*self*, *other*[, *modulo*])[¶](#object.__ipow__ "Link to this definition")
object.\_\_ilshift\_\_(*self*, *other*)[¶](#object.__ilshift__ "Link to this definition")
object.\_\_irshift\_\_(*self*, *other*)[¶](#object.__irshift__ "Link to this definition")
object.\_\_iand\_\_(*self*, *other*)[¶](#... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
3a5b269b-41e9-581b-b515-d8a7605bd1a6 | docs | python | python_datamodel | 313 | 156 | augmented assignment falls back to the normal methods. For instance, if *x*
is an instance of a class with an [`__iadd__()`](#object.__iadd__ "object.__iadd__") method, `x += y` is
equivalent to `x = x.__iadd__(y)` . If [`__iadd__()`](#object.__iadd__ "object.__iadd__") does not exist, or if `x.__iadd__(y)`... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
90afda1d-9eaa-56bc-97c9-15a3edc9cb4f | docs | python | python_datamodel | 313 | 157 | object.\_\_invert\_\_(*self*)[¶](#object.__invert__ "Link to this definition")
: Called to implement the unary arithmetic operations (`-`, `+`, [`abs()`](../library/functions.html#abs "abs")
and `~`).
object.\_\_complex\_\_(*self*)[¶](#object.__complex__ "Link to this definition")
object.\_\_int\_\_(*self*)[¶](... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
ddc7cc40-48c9-5cfe-b3b4-103b025b676a | docs | python | python_datamodel | 313 | 158 | slicing, or in the built-in [`bin()`](../library/functions.html#bin "bin"), [`hex()`](../library/functions.html#hex "hex") and [`oct()`](../library/functions.html#oct "oct")
functions). Presence of this method indicates that the numeric object is
an integer type. Must return an integer.
If [`__int__()`... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
a2b79d66-8213-5e17-80e4-3c5697cf5e44 | docs | python | python_datamodel | 313 | 159 | object.\_\_ceil\_\_(*self*)[¶](#object.__ceil__ "Link to this definition")
: Called to implement the built-in function [`round()`](../library/functions.html#round "round") and [`math`](../library/math.html#module-math "math: Mathematical functions (sin() etc.).")
functions [`trunc()`](../library/math.html#math.tr... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
07f3c866-193f-53db-bc6f-fc267e2ce9d7 | docs | python | python_datamodel | 313 | 160 | Changed in version 3.11: The delegation of [`int()`](../library/functions.html#int "int") to [`__trunc__()`](#object.__trunc__ "object.__trunc__") is deprecated.
### 3.3.9. With Statement Context Managers[¶](#with-statement-context-managers "Link to this heading")
A *context manager* is an object that defines the... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
14355a8b-494e-582e-92a0-25904c805b7d | docs | python | python_datamodel | 313 | 161 | The [`object`](../library/functions.html#object "object") class itself does not provide the context manager methods.
object.\_\_enter\_\_(*self*)[¶](#object.__enter__ "Link to this definition")
: Enter the runtime context related to this object. The [`with`](compound_stmts.html#with) statement
will bind this met... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
dde827e3-c075-5f41-87b5-480d1e412baa | docs | python | python_datamodel | 313 | 162 | Otherwise, the exception will be processed normally upon exit from this method.
Note that [`__exit__()`](#object.__exit__ "object.__exit__") methods should not reraise the passed-in exception;
this is the caller’s responsibility.
See also
[**PEP 343**](https://peps.python.org/pep-0343/) - The “with” stat... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
38b2a755-559c-51ac-8790-ec4d692795ab | docs | python | python_datamodel | 313 | 163 | : This class variable can be assigned a tuple of strings. When this class is
used in a class pattern with positional arguments, each positional argument will
be converted into a keyword argument, using the corresponding value in
*\_\_match\_args\_\_* as the keyword. The absence of this attribute is equiva... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
09f4cbd8-845a-5d14-b808-83f2be3ce7f4 | docs | python | python_datamodel | 313 | 164 | ### 3.3.11. Emulating buffer types[¶](#emulating-buffer-types "Link to this heading")
The [buffer protocol](../c-api/buffer.html#bufferobjects) provides a way for Python
objects to expose efficient access to a low-level memory array. This protocol
is implemented by builtin types such as [`bytes`](../library/stdtypes.h... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
9f4aa156-63cc-5992-b0db-c5bf0af606f6 | docs | python | python_datamodel | 313 | 165 | the returned buffer is read-only or writable. [`inspect.BufferFlags`](../library/inspect.html#inspect.BufferFlags "inspect.BufferFlags")
provides a convenient way to interpret the flags. The method must return
a [`memoryview`](../library/stdtypes.html#memoryview "memoryview") object.
object.\_\_release\_bu... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
44336007-4547-50c4-ba58-31e2c9b60276 | docs | python | python_datamodel | 313 | 166 | : Introduces the Python `__buffer__` and `__release_buffer__` methods.
[`collections.abc.Buffer`](../library/collections.abc.html#collections.abc.Buffer "collections.abc.Buffer")
: ABC for buffer types.
### 3.3.12. Special method lookup[¶](#special-method-lookup "Link to this heading")
For custom classes, implic... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
ce4847fa-8099-53f6-981a-2aaa9f3af3c1 | docs | python | python_datamodel | 313 | 167 | including type objects. If the implicit lookup of these methods used the
conventional lookup process, they would fail when invoked on the type object
itself:
```None
>>> 1 .__hash__() == hash(1)
True
>>> int.__hash__() == hash(int)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: des... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
7e4e0da2-1d20-5ac3-9fbd-bfc6c9e6fa48 | docs | python | python_datamodel | 313 | 168 | ... print("Metaclass getattribute invoked")
... return type.__getattribute__(*args)
...
>>> class C(object, metaclass=Meta):
... def __len__(self):
... return 10
... def __getattribute__(*args):
... print("Class getattribute invoked")
... return object.__getattribute__(*a... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
9f346a48-657f-57a7-a6b5-35c04371f594 | docs | python | python_datamodel | 313 | 169 | ## 3.4. Coroutines[¶](#coroutines "Link to this heading")
### 3.4.1. Awaitable Objects[¶](#awaitable-objects "Link to this heading")
An [awaitable](../glossary.html#term-awaitable) object generally implements an [`__await__()`](#object.__await__ "object.__await__") method.
[Coroutine objects](../glossary.html#term-co... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
3b70566c-568a-5869-b270-398df3bc4ca2 | docs | python | python_datamodel | 313 | 170 | [awaitable](../glossary.html#term-awaitable) objects. For instance, [`asyncio.Future`](../library/asyncio-future.html#asyncio.Future "asyncio.Future") implements
this method to be compatible with the [`await`](expressions.html#await) expression.
The [`object`](../library/functions.html#object "object") clas... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
c2ccdf24-0019-5696-a7dc-97c976c328be | docs | python | python_datamodel | 313 | 171 | ### 3.4.2. Coroutine Objects[¶](#coroutine-objects "Link to this heading")
[Coroutine objects](../glossary.html#term-coroutine) are [awaitable](../glossary.html#term-awaitable) objects.
A coroutine’s execution can be controlled by calling [`__await__()`](#object.__await__ "object.__await__") and
iterating over the res... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
03dbacf2-6a70-5022-92e0-cf669ed242e0 | docs | python | python_datamodel | 313 | 172 | generators, coroutines do not directly support iteration.
Changed in version 3.5.2: It is a [`RuntimeError`](../library/exceptions.html#RuntimeError "RuntimeError") to await on a coroutine more than once.
coroutine.send(*value*)[¶](#coroutine.send "Link to this definition")
: Starts or resumes execution of the coro... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
61ee8a83-f6b0-5b71-a79c-2e734f441103 | docs | python | python_datamodel | 313 | 173 | : Raises the specified exception in the coroutine. This method delegates
to the [`throw()`](expressions.html#generator.throw "generator.throw") method of the iterator that caused
the coroutine to suspend, if it has such a method. Otherwise,
the exception is raised at the suspension point. The result
(... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
473b44a3-e550-539b-8743-aaf3292f7c46 | docs | python | python_datamodel | 313 | 174 | is suspended, this method first delegates to the [`close()`](expressions.html#generator.close "generator.close")
method of the iterator that caused the coroutine to suspend, if it
has such a method. Then it raises [`GeneratorExit`](../library/exceptions.html#GeneratorExit "GeneratorExit") at the
suspens... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
c9f07556-dcb1-515b-88c4-4bb40db34db4 | docs | python | python_datamodel | 313 | 175 | object.\_\_aiter\_\_(*self*)[¶](#object.__aiter__ "Link to this definition")
: Must return an *asynchronous iterator* object.
object.\_\_anext\_\_(*self*)[¶](#object.__anext__ "Link to this definition")
: Must return an *awaitable* resulting in a next value of the iterator. Should
raise a [`StopAsyncIteration`... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
dcb964e7-d4d2-5c3c-bbe5-f9c6bad1d888 | docs | python | python_datamodel | 313 | 176 | Starting with Python 3.7, [`__aiter__()`](#object.__aiter__ "object.__aiter__") must return an
asynchronous iterator object. Returning anything else
will result in a [`TypeError`](../library/exceptions.html#TypeError "TypeError") error.
### 3.4.4. Asynchronous Context Managers[¶](#asynchronous-context-managers "Link t... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
da32d07d-0ffe-5b05-b089-c7cf6b747f49 | docs | python | python_datamodel | 313 | 177 | object.\_\_aexit\_\_(*self*, *exc\_type*, *exc\_value*, *traceback*)[¶](#object.__aexit__ "Link to this definition")
: Semantically similar to [`__exit__()`](#object.__exit__ "object.__exit__"), the only
difference being that it must return an *awaitable*.
An example of an asynchronous context manager class:
``... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
e3dfdfbc-7752-5f08-9943-2aa25fb76667 | docs | python | python_datamodel | 313 | 178 | [`__reversed__()`](#object.__reversed__ "object.__reversed__"), [`__contains__()`](#object.__contains__ "object.__contains__"),
[`__class_getitem__()`](#object.__class_getitem__ "object.__class_getitem__") and [`__fspath__()`](../library/os.html#os.PathLike.__fspath__ "os.PathLike.__fspath__")
methods have special hand... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
d440aa1c-ad78-59da-8485-180ee234c6c6 | docs | python | python_datamodel | 313 | 179 | method – such as [`__add__()`](#object.__add__ "object.__add__") – fails then the overall
operation is not
supported, which is why the reflected method is not called.
| large_dataset/raw/docs/python/datamodel/datamodel_313.md |
a1b1c630-8bd1-565c-8176-ea721aedd3f9 | docs | python | python_datamodel | 314 | 0 | # 3.Data model¶
Source: https://docs.python.org/3.14/reference/datamodel.html
Version: 3.14
## 3.1. Objects, values and types[¶](#objects-values-and-types "Link to this heading")
*Objects* are Python’s abstraction for data. All data in a Python program
is represented by objects or by relations between objects. Even ... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
d10f1680-5a38-5845-b9e8-b666a9f5cdef | docs | python | python_datamodel | 314 | 1 | type. The [`type()`](../library/functions.html#type "type") function returns an object’s type (which is an object
itself). Like its identity, an object’s *type* is also unchangeable.
[[1]](#id20)
The *value* of some objects can change. Objects whose value can
change are said to be *mutable*; objects whose value is unc... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
600620cd-4765-570c-be63-4b1da0566912 | docs | python | python_datamodel | 314 | 2 | they may be garbage-collected. An implementation is allowed to postpone garbage
collection or omit it altogether — it is a matter of implementation quality
how garbage collection is implemented, as long as no objects are collected that
are still reachable.
**CPython implementation detail:** CPython currently uses a re... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
92396682-fb44-5693-8856-f364526f691d | docs | python | python_datamodel | 314 | 3 | keep objects alive that would normally be collectable. Also note that catching
an exception with a [`try`](compound_stmts.html#try)…[`except`](compound_stmts.html#except) statement may keep
objects alive.
Some objects contain references to “external” resources such as open files or
windows. It is understood that these... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
712c2558-7ccc-5c86-8573-450806de3983 | docs | python | python_datamodel | 314 | 4 | container, we imply the values, not the identities of the contained objects;
however, when we talk about the mutability of a container, only the identities
of the immediately contained objects are implied. So, if an immutable container
(like a tuple) contains a reference to a mutable object, its value changes if
that m... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
33f78df2-5c5a-54a7-9c22-cec9b37875e9 | docs | python | python_datamodel | 314 | 5 | not be relied upon, but is something to be aware of when making use of object
identity tests.
However, after `c = []; d = []`, *c* and *d* are guaranteed to refer to two
different, unique, newly created empty lists. (Note that `e = f = []` assigns
the *same* object to both *e* and *f*.)
## 3.2. The standard type hiera... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
1e4d717c-6d1a-5cb1-8bff-9a6599720051 | docs | python | python_datamodel | 314 | 6 | ### 3.2.1. None[¶](#none "Link to this heading")
This type has a single value. There is a single object with this value. This
object is accessed through the built-in name `None`. It is used to signify the
absence of a value in many situations, e.g., it is returned from functions that
don’t explicitly return anything. ... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
c0e8da84-2a97-5b09-8838-ffc8ba4d56a5 | docs | python | python_datamodel | 314 | 7 | for more details.
Changed in version 3.9: Evaluating [`NotImplemented`](../library/constants.html#NotImplemented "NotImplemented") in a boolean context was deprecated.
Changed in version 3.14: Evaluating [`NotImplemented`](../library/constants.html#NotImplemented "NotImplemented") in a boolean context now raises a [`... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
e39fe7b7-71da-5ed8-8311-98404fea8a66 | docs | python | python_datamodel | 314 | 8 | ### 3.2.4. [`numbers.Number`](../library/numbers.html#numbers.Number "numbers.Number")[¶](#numbers-number "Link to this heading")
These are created by numeric literals and returned as results by arithmetic
operators and arithmetic built-in functions. Numeric objects are immutable;
once created their value never change... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
ab33e505-08a4-5c6f-bd77-c0c7b7b8e5c9 | docs | python | python_datamodel | 314 | 9 | decimal point, are not shown.
* A sign is shown only when the number is negative.
Python distinguishes between integers, floating-point numbers, and complex
numbers:
#### 3.2.4.1. [`numbers.Integral`](../library/numbers.html#numbers.Integral "numbers.Integral")[¶](#numbers-integral "Link to this heading")
These re... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
a78947e1-ab0a-5e01-a6ba-4ae2fe4dfc87 | docs | python | python_datamodel | 314 | 10 | Booleans ([`bool`](../library/functions.html#bool "bool"))
: These represent the truth values False and True. The two objects representing
the values `False` and `True` are the only Boolean objects. The Boolean type is a
subtype of the integer type, and Boolean values behave like the values 0 and 1,
respe... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
266ba4be-7c44-5417-b3af-174fb925c02c | docs | python | python_datamodel | 314 | 11 | memory usage that are usually the reason for using these are dwarfed by the
overhead of using objects in Python, so there is no reason to complicate the
language with two kinds of floating-point numbers.
#### 3.2.4.3. [`numbers.Complex`](../library/numbers.html#numbers.Complex "numbers.Complex") ([`complex`](../librar... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
19d21c86-19eb-52dd-887e-dcefc694f41a | docs | python | python_datamodel | 314 | 12 | …, *n*-1. Item *i* of sequence *a* is selected by `a[i]`. Some sequences,
including built-in sequences, interpret negative subscripts by adding the
sequence length. For example, `a[-2]` equals `a[n-2]`, the second to last
item of sequence a with length `n`.
The resulting value must be a nonnegative integer less than t... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
1595a861-eef9-5e10-8a34-b1bda4edc8b3 | docs | python | python_datamodel | 314 | 13 | the length of the sequence.
Some sequences also support “extended slicing” with a third “step” parameter:
`a[i:j:k]` selects all items of *a* with index *x* where `x = i + n*k`, *n*
`>=` `0` and *i* `<=` *x* `<` *j*.
Sequences are distinguished according to their mutability:
#### 3.2.5.1. Immutable sequences[¶](#imm... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
74a51bbd-16e1-5404-b52d-9d86b235d52a | docs | python | python_datamodel | 314 | 14 | Instead, every code point in the string is represented as a string
object with length `1`.
The built-in function [`ord()`](../library/functions.html#ord "ord")
converts a code point from its string form to an integer in the
range `0` to `0x10FFFF`; [`chr()`](../library/functions.html#chr "chr") con... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
ba338bd9-a302-5c42-98fd-5dfbf9d7b6f7 | docs | python | python_datamodel | 314 | 15 | of one item (a ‘singleton’) can be formed by affixing a comma to an
expression (an expression by itself does not create a tuple, since
parentheses must be usable for grouping of expressions). An empty
tuple can be formed by an empty pair of parentheses.
Bytes
: A [`bytes`](../library/stdtypes.html#by... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
cbfb7f9f-199c-5434-9b3c-32fae7874c3a | docs | python | python_datamodel | 314 | 16 | The [`collections`](../library/collections.html#module-collections "collections: Container datatypes") and [`array`](../library/array.html#module-array "array: Space efficient arrays of uniformly typed numeric values.") module provide
additional examples of mutable sequence types.
There are currently two intrinsic mut... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
94c07519-88fd-5ebc-93bc-9703232288b2 | docs | python | python_datamodel | 314 | 17 | ### 3.2.6. Set types[¶](#set-types "Link to this heading")
These represent unordered, finite sets of unique, immutable objects. As such,
they cannot be indexed by any subscript. However, they can be iterated over, and
the built-in function [`len()`](../library/functions.html#len "len") returns the number of items in a... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
1bfd1ce9-2bca-5395-8216-e4d55dd67beb | docs | python | python_datamodel | 314 | 18 | [`add()`](../library/stdtypes.html#set.add "set.add").
Frozen sets
: These represent an immutable set. They are created by the built-in
[`frozenset()`](../library/stdtypes.html#frozenset "frozenset") constructor. As a frozenset is immutable and
[hashable](../glossary.html#term-hashable), it can be used a... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
8feef5c9-a0f0-5bd4-8b05-c25246025e01 | docs | python | python_datamodel | 314 | 19 | #### 3.2.7.1. Dictionaries[¶](#dictionaries "Link to this heading")
These represent finite sets of objects indexed by nearly arbitrary values. The
only types of values not acceptable as keys are values containing lists or
dictionaries or other mutable types that are compared by value rather than by
object identity, th... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
91f1afd8-1e52-55f7-8457-f52f273f4413 | docs | python | python_datamodel | 314 | 20 | section [Dictionary displays](expressions.html#dict)).
The extension modules [`dbm.ndbm`](../library/dbm.html#module-dbm.ndbm "dbm.ndbm: The New Database Manager (Unix)") and [`dbm.gnu`](../library/dbm.html#module-dbm.gnu "dbm.gnu: GNU database manager (Unix)") provide
additional examples of mapping types, as does the... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
5b65b981-ea26-56ec-a0ee-0c4820415b4d | docs | python | python_datamodel | 314 | 21 | #### 3.2.8.1. User-defined functions[¶](#user-defined-functions "Link to this heading")
A user-defined function object is created by a function definition (see
section [Function definitions](compound_stmts.html#function)). It should be called with an argument list
containing the same number of items as the function’s ... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
34e6ca25-fd38-532b-8cea-b9877aa3e4cc | docs | python | python_datamodel | 314 | 22 | | function.\_\_closure\_\_[¶](#function.__closure__ "Link to this definition") | `None` or a [`tuple`](../library/stdtypes.html#tuple "tuple") of cells that contain bindings for the names specified in the [`co_freevars`](#codeobject.co_freevars "codeobject.co_freevars") attribute of the function’s [`code object`](#func... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
d696c3ce-0641-55cf-82fa-b4aa28d6ec3c | docs | python | python_datamodel | 314 | 23 | | function.\_\_qualname\_\_[¶](#function.__qualname__ "Link to this definition") | The function’s [qualified name](../glossary.html#term-qualified-name). See also: [`__qualname__ attributes`](../library/stdtypes.html#definition.__qualname__ "definition.__qualname__"). Added in version 3.3. |
| function.\_\_module\_\_[... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
57684185-d3b9-5b68-8aa0-290a4a2201e1 | docs | python | python_datamodel | 314 | 24 | | function.\_\_dict\_\_[¶](#function.__dict__ "Link to this definition") | The namespace supporting arbitrary function attributes. See also: [`__dict__ attributes`](#object.__dict__ "object.__dict__"). |
| function.\_\_annotations\_\_[¶](#function.__annotations__ "Link to this definition") | A [`dictionary`](../library... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
2924aeae-e86c-5ffb-8d69-e458eeee3cb4 | docs | python | python_datamodel | 314 | 25 | | function.\_\_annotate\_\_[¶](#function.__annotate__ "Link to this definition") | The [annotate function](../glossary.html#term-annotate-function) for this function, or `None` if the function has no annotations. See [`object.__annotate__`](#object.__annotate__ "object.__annotate__"). Added in version 3.14. |
| functi... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
4bd9683d-fb99-5833-acad-80b0d37ea0f7 | docs | python | python_datamodel | 314 | 26 | dot-notation is used to get and set such attributes.
**CPython implementation detail:** CPython’s current implementation only supports function attributes
on user-defined functions. Function attributes on
[built-in functions](#builtin-functions) may be supported in the
future.
Additional information about a function’... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
d18f9e6a-0f69-52d4-8f44-7e442bc1ae0f | docs | python | python_datamodel | 314 | 27 | | method.\_\_doc\_\_[¶](#method.__doc__ "Link to this definition") | The method’s documentation (same as [`method.__func__.__doc__`](#function.__doc__ "function.__doc__")). A [`string`](../library/stdtypes.html#str "str") if the original function had a docstring, else `None`. |
| method.\_\_name\_\_[¶](#method.__name__... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
101228de-fd46-5028-b1b9-2846999e31d7 | docs | python | python_datamodel | 314 | 28 | [`classmethod`](../library/functions.html#classmethod "classmethod") object.
When an instance method object is created by retrieving a user-defined
[function object](#user-defined-funcs) from a class via one of its
instances, its [`__self__`](#method.__self__ "method.__self__") attribute is the instance, and the
metho... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
abf66ce2-d36b-5443-bda6-fe0d6cb25d50 | docs | python | python_datamodel | 314 | 29 | ([`__self__`](#method.__self__ "method.__self__")) in front of the argument list. For instance, when
`C` is a class which contains a definition for a function
`f()`, and `x` is an instance of `C`, calling `x.f(1)` is
equivalent to calling `C.f(x, 1)`.
When an instance method object is derived from a [`classmethod`](..... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
b45c29f8-0798-5c49-99af-0f4e9ea2886f | docs | python | python_datamodel | 314 | 30 | #### 3.2.8.3. Generator functions[¶](#generator-functions "Link to this heading")
A function or method which uses the [`yield`](simple_stmts.html#yield) statement (see section
[The yield statement](simple_stmts.html#yield)) is called a *generator function*. Such a function, when
called, always returns an [iterator](..... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
6b369d58-b8db-5f82-b49b-d0b04d1388b0 | docs | python | python_datamodel | 314 | 31 | #### 3.2.8.4. Coroutine functions[¶](#coroutine-functions "Link to this heading")
A function or method which is defined using [`async def`](compound_stmts.html#async-def) is called
a *coroutine function*. Such a function, when called, returns a
[coroutine](../glossary.html#term-coroutine) object. It may contain [`awai... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
a80659a2-a006-5e80-bc07-b65581b04ce4 | docs | python | python_datamodel | 314 | 32 | [`async for`](compound_stmts.html#async-for) statement to execute the body of the function.
Calling the asynchronous iterator’s
[`aiterator.__anext__`](#object.__anext__ "object.__anext__") method
will return an [awaitable](../glossary.html#term-awaitable) which when awaited
will execute until it provides a value usin... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
283020a6-8ec5-5c7d-b28c-6df9031993d2 | docs | python | python_datamodel | 314 | 33 | built-in functions are [`len()`](../library/functions.html#len "len") and [`math.sin()`](../library/math.html#math.sin "math.sin") ([`math`](../library/math.html#module-math "math: Mathematical functions (sin() etc.).") is a
standard built-in module). The number and type of the arguments are
determined by the C functio... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
ffe574d4-0944-5d3e-9c16-dd3d8ac80770 | docs | python | python_datamodel | 314 | 34 | #### 3.2.8.7. Built-in methods[¶](#built-in-methods "Link to this heading")
This is really a different disguise of a built-in function, this time containing
an object passed to the C function as an implicit extra argument. An example of
a built-in method is `alist.append()`, assuming *alist* is a list object. In
this ... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
f5f3583e-55c2-5e98-8768-efc9b3c54d2c | docs | python | python_datamodel | 314 | 35 | #### 3.2.8.9. Class Instances[¶](#class-instances "Link to this heading")
Instances of arbitrary classes can be made callable by defining a
[`__call__()`](#object.__call__ "object.__call__") method in their class.
### 3.2.9. Modules[¶](#modules "Link to this heading")
Modules are a basic organizational unit of Pytho... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
5aafa1a6-3b8b-5a34-925c-91a7892414b8 | docs | python | python_datamodel | 314 | 36 | translated to lookups in this dictionary, e.g., `m.x` is equivalent to
`m.__dict__["x"]`. A module object does not contain the code object used
to initialize the module (since it isn’t needed once the initialization is
done).
Attribute assignment updates the module’s namespace dictionary, e.g.,
`m.x = 1` is equivalent... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
77860d0c-5696-55fe-855f-cf36598bdd19 | docs | python | python_datamodel | 314 | 37 | it’s recommended to use [`importlib.util.module_from_spec()`](../library/importlib.html#importlib.util.module_from_spec "importlib.util.module_from_spec"),
which will set the various import-controlled attributes to appropriate values.
It’s also possible to use the [`types.ModuleType`](../library/types.html#types.Module... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
1c40fe68-a6e9-5c4c-9b6b-af03a42fc797 | docs | python | python_datamodel | 314 | 38 | >>> typing.__spec__.name = 'spelling'
>>> typing.__name__, typing.__spec__.name
('typing', 'spelling')
>>> typing.__name__ = 'keyboard_smashing'
>>> typing.__name__, typing.__spec__.name
('keyboard_smashing', 'spelling')
```
module.\_\_name\_\_[¶](#module.__name__ "Link to this definition")
: The name used to unique... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
03cb2a56-e3da-5f40-842e-a0cc77e77d7e | docs | python | python_datamodel | 314 | 39 | used when importing the module. See [Module specs](import.html#module-specs) for more details.
Added in version 3.4.
module.\_\_package\_\_[¶](#module.__package__ "Link to this definition")
: The [package](../glossary.html#term-package) a module belongs to.
If the module is top-level (that is, not a pa... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
1070c18e-817a-5748-b049-9d1fc1775294 | docs | python | python_datamodel | 314 | 40 | use [`importlib.util.module_from_spec()`](../library/importlib.html#importlib.util.module_from_spec "importlib.util.module_from_spec") instead to ensure the attribute
is set to a [`str`](../library/stdtypes.html#str "str").
It is **strongly** recommended that you use
[`module.__spec__.parent`](../libra... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
7422c5eb-ae3a-529e-92ab-3f2c29911082 | docs | python | python_datamodel | 314 | 41 | [`__spec__.parent`](../library/importlib.html#importlib.machinery.ModuleSpec.parent "importlib.machinery.ModuleSpec.parent").
[`__package__`](#module.__package__ "module.__package__") is now only used as a fallback during import
resolution if `__spec__.parent` is not defined.
Changed in version 3.10: [... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
e73e7c80-7e3e-5d3b-825c-ab2cfbdf22e6 | docs | python | python_datamodel | 314 | 42 | by the import system or standard library.
module.\_\_loader\_\_[¶](#module.__loader__ "Link to this definition")
: The [loader](../glossary.html#term-loader) object that the import machinery used to load the module.
This attribute is mostly useful for introspection, but can be used for
additional loader... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
c03c6f8f-ca5a-5188-b39c-f664c1c922c5 | docs | python | python_datamodel | 314 | 43 | instead of `module.__loader__`.
Changed in version 3.4: This attribute now defaults to `None` for modules created dynamically
using the [`types.ModuleType`](../library/types.html#types.ModuleType "types.ModuleType") constructor.
Previously the attribute was optional.
Deprecated since version 3.12,... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
640f113d-1022-5b17-be03-d0edb97090ec | docs | python | python_datamodel | 314 | 44 | [`module.__spec__.submodule_search_locations`](../library/importlib.html#importlib.machinery.ModuleSpec.submodule_search_locations "importlib.machinery.ModuleSpec.submodule_search_locations")
instead of `module.__path__`.
module.\_\_file\_\_[¶](#module.__file__ "Link to this definition")
module.\_\_cached\_\_... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
75febb1a-2fa8-51f1-b146-5a4d1d3e8fac | docs | python | python_datamodel | 314 | 45 | has no semantic meaning (for example, a module loaded from a database).
If `__file__` is set then the `__cached__` attribute might
also be set, which is the path to any compiled version of
the code (for example, a byte-compiled file). The file does not need to exist
to set this attribute; the path ... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
20083175-94b5-570e-96dc-6382595af564 | docs | python | python_datamodel | 314 | 46 | [`module.__spec__.cached`](../library/importlib.html#importlib.machinery.ModuleSpec.cached "importlib.machinery.ModuleSpec.cached")
instead of `module.__cached__`.
Deprecated since version 3.13, will be removed in version 3.15: Setting `__cached__` on a module while failing to set
`__spec__.cached` is ... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
74127bff-3b31-5e85-8743-b0a89409492c | docs | python | python_datamodel | 314 | 47 | : A dictionary containing [variable annotations](../glossary.html#term-variable-annotation)
collected during module body execution. For best practices on working with
`__annotations__`, see [`annotationlib`](../library/annotationlib.html#module-annotationlib "annotationlib: Functionality for introspecting ann... | large_dataset/raw/docs/python/datamodel/datamodel_314.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.