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
36b65fce-d984-5519-b5f2-a9ebaf01fa13
docs
python
python_datamodel
315
61
| codeobject.co\_code[¶](#codeobject.co_code "Link to this definition") | A string representing the sequence of [bytecode](../glossary.html#term-bytecode) instructions in the function | | codeobject.co\_consts[¶](#codeobject.co_consts "Link to this definition") | A [`tuple`](../library/stdtypes.html#tuple "tuple") cont...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
6eee70de-82c2-5b6a-970d-bf10990a46fa
docs
python
python_datamodel
315
62
| codeobject.co\_lnotab[¶](#codeobject.co_lnotab "Link to this definition") | A string encoding the mapping from [bytecode](../glossary.html#term-bytecode) offsets to line numbers. For details, see the source code of the interpreter. Deprecated since version 3.12: This attribute of code objects is deprecated, and may ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
4180af8a-1a95-50f4-8fe0-7e66398d77a2
docs
python
python_datamodel
315
63
if the function is a generator. See [Code Objects Bit Flags](../library/inspect.html#inspect-module-co-flags) for details on the semantics of each flags that might be present. Future feature declarations (for example, `from __future__ import division`) also use bits in [`co_flags`](#codeobject.co_flags "codeobject.co_...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
8f20107e-45ce-5974-8f12-bd561daa7b01
docs
python
python_datamodel
315
64
##### 3.2.13.1.2. Methods on code objects[¶](#methods-on-code-objects "Link to this heading") codeobject.co\_positions()[¶](#codeobject.co_positions "Link to this definition") : Returns an iterable over the source code positions of each [bytecode](../glossary.html#term-bytecode) instruction in the code object. ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
1c9b94a6-0a2b-5b6c-94cc-169f4999070d
docs
python
python_datamodel
315
65
* Position tuples corresponding to artificial instructions. * Line and column numbers that can’t be represented due to implementation specific limitations. When this occurs, some or all of the tuple elements can be [`None`](../library/constants.html#None "None"). Added in version 3.11. ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
974a9c6a-cd9f-5c0c-9275-04f5ca7b0fbd
docs
python
python_datamodel
315
66
[bytecode](../glossary.html#term-bytecode)s. Each item yielded is a `(start, end, lineno)` [`tuple`](../library/stdtypes.html#tuple "tuple"): * `start` (an [`int`](../library/functions.html#int "int")) represents the offset (inclusive) of the start of the [bytecode](../glossary.html#term-bytecode) ra...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
6df53408-af72-5d77-be17-0decf94c3b30
docs
python
python_datamodel
315
67
is, for any pair of [`tuple`](../library/stdtypes.html#tuple "tuple")s, the `start` of the second will be equal to the `end` of the first. * No range will be backwards: `end >= start` for all triples. * The last [`tuple`](../library/stdtypes.html#tuple "tuple") yielded will have `end` equal to the s...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
9df5506a-2f96-58f3-a497-9c358ba96a3f
docs
python
python_datamodel
315
68
Code objects are also supported by the generic function [`copy.replace()`](../library/copy.html#copy.replace "copy.replace"). Added in version 3.8. #### 3.2.13.2. Frame objects[¶](#frame-objects "Link to this heading") Frame objects represent execution frames. They may occur in [traceback objects](#traceback...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
0a94322d-20df-5638-9c43-940b3328344e
docs
python
python_datamodel
315
69
| frame.f\_locals[¶](#frame.f_locals "Link to this definition") | The mapping used by the frame to look up [local variables](executionmodel.html#naming). If the frame refers to an [optimized scope](../glossary.html#term-optimized-scope), this may return a write-through proxy object. Changed in version 3.13: Return a p...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
c0d2f266-8bcb-507f-91c9-ad33dab60b89
docs
python
python_datamodel
315
70
| frame.f\_generator[¶](#frame.f_generator "Link to this definition") | The [generator](../glossary.html#term-generator) or [coroutine](../glossary.html#term-coroutine) object that owns this frame, or `None` if the frame is a normal function. Added in version 3.14. | ##### 3.2.13.2.2. Special writable attributes[¶](#...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
66b98b12-0af3-5dac-94a2-203c4c842e7b
docs
python
python_datamodel
315
71
| frame.f\_trace\_opcodes[¶](#frame.f_trace_opcodes "Link to this definition") | Set this attribute to [`True`](../library/constants.html#True "True") to allow per-opcode events to be requested. Note that this may lead to undefined interpreter behaviour if exceptions raised by the trace function escape to the function ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
1ae72c2a-8f3b-5887-bd43-9c4b4c4d093f
docs
python
python_datamodel
315
72
frame. Also, if the frame belonged to a [generator](../glossary.html#term-generator), the generator is finalized. This helps break reference cycles involving frame objects (for example when catching an [exception](../library/exceptions.html#bltin-exceptions) and storing its [traceback](#traceback-object...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
5214fb6d-71d2-5d14-9a7c-aec655e64216
docs
python
python_datamodel
315
73
created by calling [`types.TracebackType`](../library/types.html#types.TracebackType "types.TracebackType"). Changed in version 3.7: Traceback objects can now be explicitly instantiated from Python code. For implicitly created tracebacks, when the search for an exception handler unwinds the execution stack, at each u...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
ec993a45-fa49-5beb-a6ba-6268b1c4e45c
docs
python
python_datamodel
315
74
as [`sys.last_traceback`](../library/sys.html#sys.last_traceback "sys.last_traceback"). For explicitly created tracebacks, it is up to the creator of the traceback to determine how the [`tb_next`](#traceback.tb_next "traceback.tb_next") attributes should be linked to form a full stack trace. Special read-only attribu...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
6d4661ee-88a2-558b-b7bd-292472532b8a
docs
python
python_datamodel
315
75
occurred in a [`try`](compound_stmts.html#try) statement with no matching except clause or with a [`finally`](compound_stmts.html#finally) clause. traceback.tb\_next[¶](#traceback.tb_next "Link to this definition") : The special writable attribute `tb_next` is the next level in the stack trace (towards the frame...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
4acae5a2-6646-54d7-b3ad-c93e3554536f
docs
python
python_datamodel
315
76
containing [`float`](../library/functions.html#float "float") objects. Special read-only attributes: [`start`](../library/functions.html#slice.start "slice.start") is the lower bound; [`stop`](../library/functions.html#slice.stop "slice.stop") is the upper bound; [`step`](../library/functions.html#slice.step "slice.st...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
5fbacd45-9db1-5bde-895e-61da87f744d7
docs
python
python_datamodel
315
77
#### 3.2.13.5. Static method objects[¶](#static-method-objects "Link to this heading") Static method objects provide a way of defeating the transformation of function objects to method objects described above. A static method object is a wrapper around any other object, usually a user-defined method object. When a sta...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
e55190a8-4737-56d3-8622-eb90fcfbd99e
docs
python
python_datamodel
315
78
described above, under [“instance methods”](#instance-methods). Class method objects are created by the built-in [`classmethod()`](../library/functions.html#classmethod "classmethod") constructor. ## 3.3. Special method names[¶](#special-method-names "Link to this heading") A class can implement certain operations th...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
92642db8-6a97-5e7e-b813-40fda16eda7d
docs
python
python_datamodel
315
79
[`AttributeError`](../library/exceptions.html#AttributeError "AttributeError") or [`TypeError`](../library/exceptions.html#TypeError "TypeError")). Setting a special method to `None` indicates that the corresponding operation is not available. For example, if a class sets [`__iter__()`](#object.__iter__ "object.__iter...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
845c58c9-40fe-531e-a519-505b38889637
docs
python
python_datamodel
315
80
in the W3C’s Document Object Model.) ### 3.3.1. Basic customization[¶](#basic-customization "Link to this heading") object.\_\_new\_\_(*cls*[, *...*])[¶](#object.__new__ "Link to this definition") : Called to create a new instance of class *cls*. [`__new__()`](#object.__new__ "object.__new__") is a static metho...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
58455d96-dc18-55e7-8be3-498ab31a755b
docs
python
python_datamodel
315
81
If [`__new__()`](#object.__new__ "object.__new__") is invoked during object construction and it returns an instance of *cls*, then the new instance’s [`__init__()`](#object.__init__ "object.__init__") method will be invoked like `__init__(self[, ...])`, where *self* is the new instance and the remaining...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
13c25b4d-4eed-5a1a-98e4-308cc3620cb1
docs
python
python_datamodel
315
82
: Called after the instance has been created (by [`__new__()`](#object.__new__ "object.__new__")), but before it is returned to the caller. The arguments are those passed to the class constructor expression. If a base class has an [`__init__()`](#object.__init__ "object.__init__") method, the derived clas...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
8c6dff8c-7412-5598-a44d-b87c7cf6607f
docs
python
python_datamodel
315
83
cause a [`TypeError`](../library/exceptions.html#TypeError "TypeError") to be raised at runtime. object.\_\_del\_\_(*self*)[¶](#object.__del__ "Link to this definition") : Called when the instance is about to be destroyed. This is also called a finalizer or (improperly) a destructor. If a base class has a ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
0ef59b3f-2595-5058-8022-669fac37e1ca
docs
python
python_datamodel
315
84
is about to be destroyed; the current [CPython](../glossary.html#term-CPython) implementation only calls it once. It is not guaranteed that [`__del__()`](#object.__del__ "object.__del__") methods are called for objects that still exist when the interpreter exits. [`weakref.finalize`](../library/wea...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
91fed236-dca9-5ee2-a12c-8e4e28da5ac4
docs
python
python_datamodel
315
85
an exception has been caught in a local variable. The frame’s locals then reference the exception, which references its own traceback, which references the locals of all frames caught in the traceback. See also Documentation for the [`gc`](../library/gc.html#module-gc "gc: Interface to the cyc...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
531bf267-8bf3-538c-af68-e8b5377381bb
docs
python
python_datamodel
315
86
to execute [`__del__()`](#object.__del__ "object.__del__"). * [`__del__()`](#object.__del__ "object.__del__") can be executed during interpreter shutdown. As a consequence, the global variables it needs to access (including other modules) may already have been deleted or set to `None`. Python ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
ce8493de-d076-5e05-a383-e250759c8390
docs
python
python_datamodel
315
87
valid Python expression that could be used to recreate an object with the same value (given an appropriate environment). If this is not possible, a string of the form `<...some useful description...>` should be returned. The return value must be a string object. If a class defines [`__repr__()`](#object...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
4f73e622-70b5-5057-a1fe-3105afd8de59
docs
python
python_datamodel
315
88
: Called by [`str(object)`](../library/stdtypes.html#str "str"), the default [`__format__()`](#object.__format__ "object.__format__") implementation, and the built-in function [`print()`](../library/functions.html#print "print"), to compute the “informal” or nicely printable string representation of an object...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
828047a1-9806-5696-9c60-688c10d06d4b
docs
python
python_datamodel
315
89
: Called by [bytes](../library/functions.html#func-bytes) to compute a byte-string representation of an object. This should return a [`bytes`](../library/stdtypes.html#bytes "bytes") object. The [`object`](../library/functions.html#object "object") class itself does not provide this method. object.\_\_format...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
29804b46-1360-5c25-96c1-92e87a78b202
docs
python
python_datamodel
315
90
delegate formatting to one of the built-in types, or use a similar formatting option syntax. See [Format Specification Mini-Language](../library/string.html#formatspec) for a description of the standard formatting syntax. The return value must be a string object. The default implementation by the...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
18fc4a32-77b1-56ae-b0ce-78715cbf4e87
docs
python
python_datamodel
315
91
object.\_\_eq\_\_(*self*, *other*)[¶](#object.__eq__ "Link to this definition") object.\_\_ne\_\_(*self*, *other*)[¶](#object.__ne__ "Link to this definition") object.\_\_gt\_\_(*self*, *other*)[¶](#object.__gt__ "Link to this definition") object.\_\_ge\_\_(*self*, *other*)[¶](#object.__ge__ "Link to this definition...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
3d7aa79a-458b-5493-8333-4dbda8f515ce
docs
python
python_datamodel
315
92
methods can return any value, so if the comparison operator is used in a Boolean context (e.g., in the condition of an `if` statement), Python will call [`bool()`](../library/functions.html#bool "bool") on the value to determine if the result is true or false. By default, `object` implements [`__eq__()...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
dc730885-89e3-5a41-ae33-225fb933ab86
docs
python
python_datamodel
315
93
operations from a single root operation, see [`functools.total_ordering()`](../library/functools.html#functools.total_ordering "functools.total_ordering"). By default, the [`object`](../library/functions.html#object "object") class provides implementations consistent with [Value comparisons](expressions.ht...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
b4f15f12-6819-5b7d-8df6-187afbcc39d3
docs
python
python_datamodel
315
94
left argument does not support the operation but the right argument does); rather, [`__lt__()`](#object.__lt__ "object.__lt__") and [`__gt__()`](#object.__gt__ "object.__gt__") are each other’s reflection, [`__le__()`](#object.__le__ "object.__le__") and [`__ge__()`](#object.__ge__ "object.__ge__") are each...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
b5476b3d-a612-535e-93c8-d6c1701e468d
docs
python
python_datamodel
315
95
object.\_\_hash\_\_(*self*)[¶](#object.__hash__ "Link to this definition") : Called by built-in function [`hash()`](../library/functions.html#hash "hash") and for operations on members of hashed collections including [`set`](../library/stdtypes.html#set "set"), [`frozenset`](../library/stdtypes.html#frozenset "fr...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
6945f127-593a-59b4-b598-959fbddb20d2
docs
python
python_datamodel
315
96
[`__hash__()`](#object.__hash__ "object.__hash__") method to the size of a [`Py_ssize_t`](../c-api/intro.html#c.Py_ssize_t "Py_ssize_t"). This is typically 8 bytes on 64-bit builds and 4 bytes on 32-bit builds. If an object’s [`__hash__()`](#object.__hash__ "object.__hash__") must interoperate on builds of ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
10d46891-2e8c-5d8e-9a2d-4f4870fb4956
docs
python
python_datamodel
315
97
[`__eq__()`](#object.__eq__ "object.__eq__") method, it should not implement [`__hash__()`](#object.__hash__ "object.__hash__"), since the implementation of [hashable](../glossary.html#term-hashable) collections requires that a key’s hash value is immutable (if the object’s hash value changes, it will be in...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
5f713787-0503-5379-8608-33261e2d16a2
docs
python
python_datamodel
315
98
[`__hash__()`](#object.__hash__ "object.__hash__") method of a class is `None`, instances of the class will raise an appropriate [`TypeError`](../library/exceptions.html#TypeError "TypeError") when a program attempts to retrieve their hash value, and will also be correctly identified as unhashable when ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
d1b9a24c-e1d1-5ce8-ad75-96788a037d40
docs
python
python_datamodel
315
99
a [`TypeError`](../library/exceptions.html#TypeError "TypeError") would be incorrectly identified as hashable by an `isinstance(obj, collections.abc.Hashable)` call. Note By default, the [`__hash__()`](#object.__hash__ "object.__hash__") values of str and bytes objects are “salted” with an unpredi...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
4f4561d4-7587-50f5-8006-d2bc548d0849
docs
python
python_datamodel
315
100
Changed in version 3.3: Hash randomization is enabled by default. object.\_\_bool\_\_(*self*)[¶](#object.__bool__ "Link to this definition") : Called to implement truth value testing and the built-in operation `bool()`; should return `False` or `True`. When this method is not defined, [`__len__()`](#obje...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
d7f9fdb6-0c3c-5005-bad0-f6b1b7a13f06
docs
python
python_datamodel
315
101
: Called when the default attribute access fails with an [`AttributeError`](../library/exceptions.html#AttributeError "AttributeError") (either [`__getattribute__()`](#object.__getattribute__ "object.__getattribute__") raises an [`AttributeError`](../library/exceptions.html#AttributeError "AttributeError") becaus...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
6436e09b-94f0-548e-ad25-c409f6a59eea
docs
python
python_datamodel
315
102
[`__getattr__()`](#object.__getattr__ "object.__getattr__") is not called. (This is an intentional asymmetry between [`__getattr__()`](#object.__getattr__ "object.__getattr__") and [`__setattr__()`](#object.__setattr__ "object.__setattr__").) This is done both for efficiency reasons and because otherwise [`...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
08ffd194-3898-5cda-bde8-d774e0f37727
docs
python
python_datamodel
315
103
class. If the class also defines [`__getattr__()`](#object.__getattr__ "object.__getattr__"), the latter will not be called unless [`__getattribute__()`](#object.__getattribute__ "object.__getattribute__") either calls it explicitly or raises an [`AttributeError`](../library/exceptions.html#AttributeError "...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
7bd4a952-e2e5-5352-9881-639353a5e4f4
docs
python
python_datamodel
315
104
For certain sensitive attribute accesses, raises an [auditing event](../library/sys.html#auditing) `object.__getattr__` with arguments `obj` and `name`. object.\_\_setattr\_\_(*self*, *name*, *value*)[¶](#object.__setattr__ "Link to this definition") : Called when an attribute assignment is attempted. Th...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
a70cf992-25fb-5e08-abe1-3b64855e085e
docs
python
python_datamodel
315
105
: Like [`__setattr__()`](#object.__setattr__ "object.__setattr__") but for attribute deletion instead of assignment. This should only be implemented if `del obj.name` is meaningful for the object. For certain sensitive attribute deletions, raises an [auditing event](../library/sys.html#auditing) `object....
large_dataset/raw/docs/python/datamodel/datamodel_315.md
18d256f9-76b5-5396-b43f-904b89bc7a71
docs
python
python_datamodel
315
106
access to module attributes. The `__getattr__` function at the module level should accept one argument which is the name of an attribute and return the computed value or raise an [`AttributeError`](../library/exceptions.html#AttributeError "AttributeError"). If an attribute is not found on a module object through the n...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
e5161d48-3073-5270-9e99-96b6f8729fd1
docs
python
python_datamodel
315
107
For a more fine grained customization of the module behavior (setting attributes, properties, etc.), one can set the `__class__` attribute of a module object to a subclass of [`types.ModuleType`](../library/types.html#types.ModuleType "types.ModuleType"). For example: ```None import sys from types import ModuleType c...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
4b59e403-c454-5c33-94b9-9d01651c0082
docs
python
python_datamodel
315
108
[**PEP 562**](https://peps.python.org/pep-0562/) - Module \_\_getattr\_\_ and \_\_dir\_\_ : Describes the `__getattr__` and `__dir__` functions on modules. #### 3.3.2.2. Implementing Descriptors[¶](#implementing-descriptors "Link to this heading") The following methods only apply when an instance of the class conta...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
7a2486ef-a61a-52d7-99ab-20bdd8e5c424
docs
python
python_datamodel
315
109
of an instance of that class (instance attribute access). The optional *owner* argument is the owner class, while *instance* is the instance that the attribute was accessed through, or `None` when the attribute is accessed through the *owner*. This method should return the computed attribute value ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
da460624-fa9d-52b1-a75e-7876ce8b5e0a
docs
python
python_datamodel
315
110
: Called to set the attribute on an instance *instance* of the owner class to a new value, *value*. Note, adding [`__set__()`](#object.__set__ "object.__set__") or [`__delete__()`](#object.__delete__ "object.__delete__") changes the kind of descriptor to a “data descriptor”. See [Invoking Descriptors](#d...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
78e0f656-7918-57b7-adbc-2280805dff27
docs
python
python_datamodel
315
111
appropriately can assist in runtime introspection of dynamic class attributes). For callables, it may indicate that an instance of the given type (or a subclass) is expected or required as the first positional argument (for example, CPython sets this attribute for unbound methods that are implemented in...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
9c17e650-5121-50d2-b463-983b8be7b5fa
docs
python
python_datamodel
315
112
starting with `a.__dict__['x']`, then `type(a).__dict__['x']`, and continuing through the base classes of `type(a)` excluding metaclasses. However, if the looked-up value is an object defining one of the descriptor methods, then Python may override the default behavior and invoke the descriptor method instead. Where t...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
ebf155aa-ca9f-58d3-b053-d79e95ee23af
docs
python
python_datamodel
315
113
`a.__class__.__mro__` for a base class `B` following `A` and then returns `B.__dict__['x'].__get__(a, A)`. If not a descriptor, `x` is returned unchanged. For instance bindings, the precedence of descriptor invocation depends on which descriptor methods are defined. A descriptor can define any combination ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
e58b527b-6c72-5abc-9bc6-67ebee31bc41
docs
python
python_datamodel
315
114
always override a redefinition in an instance dictionary. In contrast, non-data descriptors can be overridden by instances. Python methods (including those decorated with [`@staticmethod`](../library/functions.html#staticmethod "staticmethod") and [`@classmethod`](../library/functions.html#classmethod "classmethod")) ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
3ca0b224-4351-50d3-b863-534486a6cba4
docs
python
python_datamodel
315
115
The space saved over using [`__dict__`](#object.__dict__ "object.__dict__") can be significant. Attribute lookup speed can be significantly improved as well. object.\_\_slots\_\_[¶](#object.__slots__ "Link to this definition") : This class variable can be assigned a string, iterable, or sequence of strings with ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
95e9c258-1d77-5cb0-85a6-f8d8c3149465
docs
python
python_datamodel
315
116
variable name raises [`AttributeError`](../library/exceptions.html#AttributeError "AttributeError"). If dynamic assignment of new variables is desired, then add `'__dict__'` to the sequence of strings in the *\_\_slots\_\_* declaration. * Without a *\_\_weakref\_\_* variable for each instance, classes defining ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
486d977f-10cd-53e2-bb3d-6101ebd65ea5
docs
python
python_datamodel
315
117
where it is defined. *\_\_slots\_\_* declared in parents are available in child classes. However, instances of a child subclass will get a [`__dict__`](#object.__dict__ "object.__dict__") and *\_\_weakref\_\_* unless the subclass also defines *\_\_slots\_\_* (which should only contain names of any *additional* ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
a19bf2d0-31f6-53a9-90d3-04d804611d1e
docs
python
python_datamodel
315
118
[`int`](../library/functions.html#int "int"), [`bytes`](../library/stdtypes.html#bytes "bytes"), and [`type`](../library/functions.html#type "type"), except [`tuple`](../library/stdtypes.html#tuple "tuple"). * Any non-string [iterable](../glossary.html#term-iterable) may be assigned to *\_\_slots\_\_*. * If a [`dicti...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
2ea269e6-13d5-5cb9-a7e3-9a4e858c70bd
docs
python
python_datamodel
315
119
but only one parent is allowed to have attributes created by slots (the other bases must have empty slot layouts) - violations raise [`TypeError`](../library/exceptions.html#TypeError "TypeError"). * If an [iterator](../glossary.html#term-iterator) is used for *\_\_slots\_\_* then a [descriptor](../glossary.html#...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
91ceff6e-5dbe-50b6-af06-c1f3661721a5
docs
python
python_datamodel
315
120
change the behavior of subclasses. This is closely related to class decorators, but where class decorators only affect the specific class they’re applied to, `__init_subclass__` solely applies to future subclasses of the class defining the method. *classmethod* object.\_\_init\_subclass\_\_(*cls*)[¶](#object.__init_su...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
236d99ce-dec2-5a64-aaeb-525842aff1bb
docs
python
python_datamodel
315
121
cls.default_name = default_name class AustralianPhilosopher(Philosopher, default_name="Bruce"): pass ``` The default implementation `object.__init_subclass__` does nothing, but raises an error if it is called with any arguments. Note The metaclass hint `metaclass` is cons...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
8dfa3712-acf1-5b94-8f26-2bd81c485a59
docs
python
python_datamodel
315
122
x = C() # Automatically calls: x.__set_name__(A, 'x') ``` If the class variable is assigned after the class is created, [`__set_name__()`](#object.__set_name__ "object.__set_name__") will not be called automatically. If needed, [`__set_name__()`](#object.__set_name__ "object.__set_name__") can...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
0d3937de-1624-5a35-a28b-a889fc6e332f
docs
python
python_datamodel
315
123
keyword argument in the class definition line, or by inheriting from an existing class that included such an argument. In the following example, both `MyClass` and `MySubclass` are instances of `Meta`: ```None class Meta(type): pass class MyClass(metaclass=Meta): pass class MySubclass(MyClass): pass ``` ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
46a91c98-f76f-5d29-a469-c98dbe65dc54
docs
python
python_datamodel
315
124
[`type`](../library/functions.html#type "type"), then an `__mro_entries__()` method is searched on the base. If an `__mro_entries__()` method is found, the base is substituted with the result of a call to `__mro_entries__()` when creating the class. The method is called with the original bases tuple ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
61c5c4c0-fbc5-5641-9ca7-3b5f14fcc1f0
docs
python
python_datamodel
315
125
: Core support for typing module and generic types. #### 3.3.3.3. Determining the appropriate metaclass[¶](#determining-the-appropriate-metaclass "Link to this heading") The appropriate metaclass for a class definition is determined as follows: * if no bases and no explicit metaclass are given, then [`type()`](../...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
723dde58-db5e-5e11-8011-bdc4a2f3ac1e
docs
python
python_datamodel
315
126
that criterion, then the class definition will fail with `TypeError`. #### 3.3.3.4. Preparing the class namespace[¶](#preparing-the-class-namespace "Link to this heading") Once the appropriate metaclass has been identified, then the class namespace is prepared. If the metaclass has a `__prepare__` attribute, it is ca...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
f8e5ca63-6ae9-5228-84f0-5f88ab3cd2f6
docs
python
python_datamodel
315
127
#### 3.3.3.5. Executing the class body[¶](#executing-the-class-body "Link to this heading") The class body is executed (approximately) as `exec(body, globals(), namespace)`. The key difference from a normal call to [`exec()`](../library/functions.html#exec "exec") is that lexical scoping allows the class body (includi...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
f727bb26-4523-57c2-96e1-ecf3ad27217d
docs
python
python_datamodel
315
128
`metaclass(name, bases, namespace, **kwds)` (the additional keywords passed here are the same as those passed to `__prepare__`). This class object is the one that will be referenced by the zero-argument form of [`super()`](../library/functions.html#super "super"). `__class__` is an implicit closure reference created b...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
c3a977d1-3800-5a75-9726-c2320cc9621f
docs
python
python_datamodel
315
129
Failing to do so will result in a [`RuntimeError`](../library/exceptions.html#RuntimeError "RuntimeError") in Python 3.8. When using the default metaclass [`type`](../library/functions.html#type "type"), or any metaclass that ultimately calls `type.__new__`, the following additional customization steps are invoked aft...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
25db4dd7-c0bd-5713-a94c-db0a7a53dbd9
docs
python
python_datamodel
315
130
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_315.md
7e4d8c69-3842-501c-81c8-1503fd786ca6
docs
python
python_datamodel
315
131
[`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_315.md
cd33d7f1-488b-52c0-a582-e4660eb4b740
docs
python
python_datamodel
315
132
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_315.md
ee41fc07-01ef-5730-a3e4-b5025447823b
docs
python
python_datamodel
315
133
### 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_315.md
7137aedf-235c-500a-898e-263336a30eed
docs
python
python_datamodel
315
134
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_315.md
327dfaa4-b849-573a-90f3-5dfb26e976bd
docs
python
python_datamodel
315
135
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_315.md
d9288709-0a3d-5bba-9bc5-ffa7cf05958a
docs
python
python_datamodel
315
136
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_315.md
195cc566-50bc-5d97-b84f-d7a7aba28481
docs
python
python_datamodel
315
137
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_315.md
a76ee051-23c8-5920-b0e5-09a425843b21
docs
python
python_datamodel
315
138
```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_315.md
b768960c-4e23-5a10-8fd9-de23563591d5
docs
python
python_datamodel
315
139
>>> # 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_315.md
fe721655-aac0-5a7e-9dce-1d8c09cbc915
docs
python
python_datamodel
315
140
### 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_315.md
ae7805c5-9812-5839-95aa-8c5e1ced5732
docs
python
python_datamodel
315
141
`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_315.md
22d14b3b-3060-51d5-a7f5-2bf498b1ce49
docs
python
python_datamodel
315
142
[`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_315.md
3620bfb4-ffac-5400-8ffe-cdb132302053
docs
python
python_datamodel
315
143
[`__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_315.md
41096c47-64f7-506e-abf8-a7f2682791d1
docs
python
python_datamodel
315
144
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_315.md
bac374c6-62fe-5092-aef4-459f56a5da9e
docs
python
python_datamodel
315
145
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_315.md
8a757ed4-a45c-5083-9ca0-d8ef1692bd58
docs
python
python_datamodel
315
146
* **sequences**, where *subscript* (also called [index](../glossary.html#term-index)) should be an integer or a [`slice`](../library/functions.html#slice "slice") object. See the [sequence documentation](#datamodel-sequences) for the expected behavior, including handling [`slice`](../library/funct...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
857f7bae-4e2c-5537-807c-82c257c68488
docs
python
python_datamodel
315
147
([`IndexError`](../library/exceptions.html#IndexError "IndexError") for sequences; [`KeyError`](../library/exceptions.html#KeyError "KeyError") for mappings). Note The sequence iteration protocol (used, for example, in [`for`](compound_stmts.html#for) loops), expects that an [`IndexError`](../library/...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
46a0ad54-b1e7-5fc7-a8ac-570841e7cc36
docs
python
python_datamodel
315
148
[`__getitem__()`](#object.__getitem__ "object.__getitem__"). This should only be implemented for mappings if the objects support changes to the values for keys, or if new keys can be added, or for sequences if elements can be replaced. The same exceptions should be raised for improper *key* values as fo...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
2ef3c447-f30e-53cf-80d7-7f9f619bc9f8
docs
python
python_datamodel
315
149
: Called by [`dict`](../library/stdtypes.html#dict "dict").[`__getitem__()`](#object.__getitem__ "object.__getitem__") to implement `self[key]` for dict subclasses when key is not in the dictionary. object.\_\_iter\_\_(*self*)[¶](#object.__iter__ "Link to this definition") : This method is called when an [iter...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
0fdd516f-c38e-59d9-aeaf-8e53ebf08884
docs
python
python_datamodel
315
150
If the [`__reversed__()`](#object.__reversed__ "object.__reversed__") method is not provided, the [`reversed()`](../library/functions.html#reversed "reversed") built-in will fall back to using the sequence protocol ([`__len__()`](#object.__len__ "object.__len__") and [`__getitem__()`](#object.__getitem__ "o...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
940ecbbc-7186-5331-8a5b-c7d5437e8557
docs
python
python_datamodel
315
151
object.\_\_contains\_\_(*self*, *item*)[¶](#object.__contains__ "Link to this definition") : Called to implement membership test operators. Should return true if *item* is in *self*, false otherwise. For mapping objects, this should consider the keys of the mapping rather than the values or the key-item pairs...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
7ad9b2fa-56cd-5958-b006-562caeec34b6
docs
python
python_datamodel
315
152
number implemented (e.g., bitwise operations for non-integral numbers) should be left undefined. object.\_\_add\_\_(*self*, *other*)[¶](#object.__add__ "Link to this definition") object.\_\_sub\_\_(*self*, *other*)[¶](#object.__sub__ "Link to this definition") object.\_\_mul\_\_(*self*, *other*)[¶](#object.__mul__ "...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
84c244cf-c137-53de-89d9-32fadf21dac8
docs
python
python_datamodel
315
153
object.\_\_rshift\_\_(*self*, *other*)[¶](#object.__rshift__ "Link to this definition") object.\_\_and\_\_(*self*, *other*)[¶](#object.__and__ "Link to this definition") object.\_\_xor\_\_(*self*, *other*)[¶](#object.__xor__ "Link to this definition") object.\_\_or\_\_(*self*, *other*)[¶](#object.__or__ "Link to thi...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
3631b1a7-f141-50ac-b34c-fc09eb1d3e44
docs
python
python_datamodel
315
154
[`__floordiv__()`](#object.__floordiv__ "object.__floordiv__") and [`__mod__()`](#object.__mod__ "object.__mod__"); it should not be related to [`__truediv__()`](#object.__truediv__ "object.__truediv__"). Note that [`__pow__()`](#object.__pow__ "object.__pow__") should be defined to accept an optional third...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
126d3b04-9caa-5e9d-9a95-8d8c1959cd03
docs
python
python_datamodel
315
155
object.\_\_rtruediv\_\_(*self*, *other*)[¶](#object.__rtruediv__ "Link to this definition") object.\_\_rfloordiv\_\_(*self*, *other*)[¶](#object.__rfloordiv__ "Link to this definition") object.\_\_rmod\_\_(*self*, *other*)[¶](#object.__rmod__ "Link to this definition") object.\_\_rdivmod\_\_(*self*, *other*)[¶](#obj...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
06cfed61-33e4-5291-8d0e-11f2ab25bf29
docs
python
python_datamodel
315
156
(`+`, `-`, `*`, `@`, `/`, `//`, `%`, [`divmod()`](../library/functions.html#divmod "divmod"), [`pow()`](../library/functions.html#pow "pow"), `**`, `<<`, `>>`, `&`, `^`, `|`) with reflected (swapped) operands. These functions are only called if the operands are of different types, when the left operand ...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
35b501f8-c0f2-5eb8-8aae-fe41ea32d319
docs
python
python_datamodel
315
157
argument if the three-argument version of the built-in [`pow()`](../library/functions.html#pow "pow") function is to be supported. Changed in version 3.14: Three-argument [`pow()`](../library/functions.html#pow "pow") now try calling [`__rpow__()`](#object.__rpow__ "object.__rpow__") if necessary. Prev...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
ec30ee7e-6345-5280-b8e4-54ae53506e71
docs
python
python_datamodel
315
158
object.\_\_imatmul\_\_(*self*, *other*)[¶](#object.__imatmul__ "Link to this definition") object.\_\_itruediv\_\_(*self*, *other*)[¶](#object.__itruediv__ "Link to this definition") object.\_\_ifloordiv\_\_(*self*, *other*)[¶](#object.__ifloordiv__ "Link to this definition") object.\_\_imod\_\_(*self*, *other*)[¶](#...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
9ecfb86f-803a-58ee-bf8e-a03c3ce92c38
docs
python
python_datamodel
315
159
(`+=`, `-=`, `*=`, `@=`, `/=`, `//=`, `%=`, `**=`, `<<=`, `>>=`, `&=`, `^=`, `|=`). These methods should attempt to do the operation in-place (modifying *self*) and return the result (which could be, but does not have to be, *self*). If a specific method is not defined, or if that method returns [`N...
large_dataset/raw/docs/python/datamodel/datamodel_315.md
f19c5e54-1497-56ad-bf1d-f9f3892913e1
docs
python
python_datamodel
315
160
[Why does a\_tuple[i] += [‘item’] raise an exception when the addition works?](../faq/programming.html#faq-augmented-assignment-tuple-error)), but this behavior is in fact part of the data model. object.\_\_neg\_\_(*self*)[¶](#object.__neg__ "Link to this definition") object.\_\_pos\_\_(*self*)[¶](#object.__p...
large_dataset/raw/docs/python/datamodel/datamodel_315.md