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
45a38588-38b2-5ca3-b650-6e5cc6d7681a
docs
python
python_datamodel
314
48
#### 3.2.9.3. Module dictionaries[¶](#module-dictionaries "Link to this heading") Module objects also have the following special read-only attribute: module.\_\_dict\_\_[¶](#module.__dict__ "Link to this definition") : The module’s namespace as a dictionary object. Uniquely among the attributes listed here, `__...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
162085ce-e7d8-52ae-9dd3-5021b93339de
docs
python
python_datamodel
314
49
[Class definitions](compound_stmts.html#class)). A class has a namespace implemented by a dictionary object. Class attribute references are translated to lookups in this dictionary, e.g., `C.x` is translated to `C.__dict__["x"]` (although there are a number of hooks which allow for other means of locating attributes). ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
1320fe62-ce3a-5ce2-855e-2eaa1a0d70a5
docs
python
python_datamodel
314
50
When it would yield a [`staticmethod`](../library/functions.html#staticmethod "staticmethod") object, it is transformed into the object wrapped by the static method object. See section [Implementing Descriptors](#descriptors) for another way in which attributes retrieved from a class may differ from those actually cont...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
2cee99a2-e9b3-5255-ac40-ae477fb725e8
docs
python
python_datamodel
314
51
| type.\_\_qualname\_\_[¶](#type.__qualname__ "Link to this definition") | The class’s [qualified name](../glossary.html#term-qualified-name). See also: [`__qualname__ attributes`](../library/stdtypes.html#definition.__qualname__ "definition.__qualname__"). | | type.\_\_module\_\_[¶](#type.__module__ "Link to this defi...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
707fd32e-2c00-5964-b83b-3dc4fa0b486f
docs
python
python_datamodel
314
52
| type.\_\_base\_\_[¶](#type.__base__ "Link to this definition") | **CPython implementation detail:** The single base class in the inheritance chain that is responsible for the memory layout of instances. This attribute corresponds to [`tp_base`](../c-api/typeobj.html#c.PyTypeObject.tp_base "PyTypeObject.tp_base") at t...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
a1c80f10-d3e6-51a4-a7a0-fd3c8d9a4280
docs
python
python_datamodel
314
53
| type.\_\_annotations\_\_[¶](#type.__annotations__ "Link to this definition") | A dictionary containing [variable annotations](../glossary.html#term-variable-annotation) collected during class body execution. See also: [`__annotations__ attributes`](#object.__annotations__ "object.__annotations__"). For best practice...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
e7f7436a-b42f-5b20-91e7-59095ba119c2
docs
python
python_datamodel
314
54
| type.\_\_annotate\_\_()[¶](#type.__annotate__ "Link to this definition") | The [annotate function](../glossary.html#term-annotate-function) for this class, or `None` if the class has no annotations. See also: [`__annotate__ attributes`](#object.__annotate__ "object.__annotate__"). Added in version 3.14. | | type.\_\...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
c10b08b9-11f5-55b2-a0cc-056dc51ee5ca
docs
python
python_datamodel
314
55
| type.\_\_firstlineno\_\_[¶](#type.__firstlineno__ "Link to this definition") | The line number of the first line of the class definition, including decorators. Setting the [`__module__`](#type.__module__ "type.__module__") attribute removes the `__firstlineno__` item from the type’s dictionary. Added in version 3.13...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
2b10f48f-ad1a-5be7-b3a1-5035bcde2407
docs
python
python_datamodel
314
56
type.\_\_subclasses\_\_()[¶](#type.__subclasses__ "Link to this definition") : Each class keeps a list of weak references to its immediate subclasses. This method returns a list of all those references still alive. The list is in definition order. Example: ```None >>> class A: pass >>> class B(A)...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
dad47638-42ce-5c0d-a7d9-3e9e9e256cc9
docs
python
python_datamodel
314
57
class method objects are also transformed; see above under “Classes”. See section [Implementing Descriptors](#descriptors) for another way in which attributes of a class retrieved via its instances may differ from the objects actually stored in the class’s [`__dict__`](#object.__dict__ "object.__dict__"). If no class a...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
51d8d6d9-71c3-57d8-88f7-1b1ccf7d8980
docs
python
python_datamodel
314
58
#### 3.2.11.1. Special attributes[¶](#id5 "Link to this heading") object.\_\_class\_\_[¶](#object.__class__ "Link to this definition") : The class to which a class instance belongs. object.\_\_dict\_\_[¶](#object.__dict__ "Link to this definition") : A dictionary or other mapping object used to store an object’s ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
9c99a875-cdef-51dc-b0a2-2ad14abbd780
docs
python
python_datamodel
314
59
[`makefile()`](../library/socket.html#socket.socket.makefile "socket.socket.makefile") method of socket objects (and perhaps by other functions or methods provided by extension modules). The objects `sys.stdin`, `sys.stdout` and `sys.stderr` are initialized to file objects corresponding to the interpreter’s standard i...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
e8865355-d6ca-5e68-ad9f-addc2bba1cd3
docs
python
python_datamodel
314
60
The difference between a code object and a function object is that the function object contains an explicit reference to the function’s globals (the module in which it was defined), while a code object contains no context; also the default argument values are stored in the function object, not in the code object (becau...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
660bb073-aa01-5b3f-8579-04b4dd37d356
docs
python
python_datamodel
314
61
| codeobject.co\_argcount[¶](#codeobject.co_argcount "Link to this definition") | The total number of positional [parameters](../glossary.html#term-parameter) (including positional-only parameters and parameters with default values) that the function has | | codeobject.co\_posonlyargcount[¶](#codeobject.co_posonlyargco...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
9c79b6df-6370-52db-9a89-de798bcedf54
docs
python
python_datamodel
314
62
| codeobject.co\_varnames[¶](#codeobject.co_varnames "Link to this definition") | A [`tuple`](../library/stdtypes.html#tuple "tuple") containing the names of the local variables in the function (starting with the parameter names) | | codeobject.co\_cellvars[¶](#codeobject.co_cellvars "Link to this definition") | A [`tu...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
63b836ef-aa41-5e46-80bb-3f7caab8bfb2
docs
python
python_datamodel
314
63
| 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_314.md
b9004c05-10d5-5df7-91e4-4f3adfd328f7
docs
python
python_datamodel
314
64
| 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_314.md
15f97abe-5469-5dd6-b08f-ac8115a11686
docs
python
python_datamodel
314
65
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_314.md
3a69af70-0160-5182-8463-a79b544325a3
docs
python
python_datamodel
314
66
##### 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_314.md
2ebf68cd-4a43-5835-961c-9761b291bb34
docs
python
python_datamodel
314
67
* 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_314.md
244ddd75-2f69-5546-ad08-cb4649cd215d
docs
python
python_datamodel
314
68
[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_314.md
631984a9-871b-5e74-9afd-814de456f882
docs
python
python_datamodel
314
69
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_314.md
3332cc95-81b5-5197-b939-2fc8f5520d97
docs
python
python_datamodel
314
70
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_314.md
0d9323bb-c5a2-51e9-ab40-6539c00ac4c0
docs
python
python_datamodel
314
71
| 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_314.md
1f4a2efc-9b6b-585b-a117-0cb3ff53e25e
docs
python
python_datamodel
314
72
| 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_314.md
125abebf-2b54-5d4f-a526-5d4b92a9f8a9
docs
python
python_datamodel
314
73
| 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_314.md
3bb7831e-d309-53c6-84fa-db28c9ed7d48
docs
python
python_datamodel
314
74
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_314.md
a8be025c-201a-5ac0-abba-8b194a1c1136
docs
python
python_datamodel
314
75
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_314.md
2cbecb46-24f7-5e5b-9855-863d3a04d801
docs
python
python_datamodel
314
76
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_314.md
5ce1def8-692a-5ef6-8a00-a9c5670e493e
docs
python
python_datamodel
314
77
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_314.md
cf9521c1-310a-5c36-9daa-ec4fc95559c6
docs
python
python_datamodel
314
78
value; each is `None` if omitted. These attributes can have any type. Slice objects support one method: slice.indices(*self*, *length*)[¶](#slice.indices "Link to this definition") : This method takes a single integer argument *length* and computes information about the slice that the slice object would describ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
79dec9f3-af5e-5a40-8c68-a3e81c1b396d
docs
python
python_datamodel
314
79
returned is the wrapped object, which is not subject to any further transformation. Static method objects are also callable. Static method objects are created by the built-in [`staticmethod()`](../library/functions.html#staticmethod "staticmethod") constructor. #### 3.2.13.6. Class method objects[¶](#class-method-obje...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
e4ed2882-f124-5c2a-8ab7-a4496ad4bcec
docs
python
python_datamodel
314
80
with special names. This is Python’s approach to *operator overloading*, allowing classes to define their own behavior with respect to language operators. For instance, if a class defines a method named [`__getitem__()`](#object.__getitem__ "object.__getitem__"), and `x` is an instance of this class, then `x[i]` is rou...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
7088e32f-1e64-5bf6-8764-816f7c6f833b
docs
python
python_datamodel
314
81
falling back to [`__getitem__()`](#object.__getitem__ "object.__getitem__")). [[2]](#id21) When implementing a class that emulates any built-in type, it is important that the emulation only be implemented to the degree that it makes sense for the object being modelled. For example, some sequences may work well with re...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
070abc0c-0168-5178-b3d9-69980e63da03
docs
python
python_datamodel
314
82
arguments are those passed to the object constructor expression (the call to the class). The return value of [`__new__()`](#object.__new__ "object.__new__") should be the new object instance (usually an instance of *cls*). Typical implementations create a new instance of the class by invoking the s...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
0579b4a3-5b2b-5511-ac2d-9d6efc040662
docs
python
python_datamodel
314
83
If [`__new__()`](#object.__new__ "object.__new__") does not return an instance of *cls*, then the new instance’s [`__init__()`](#object.__init__ "object.__init__") method will not be invoked. [`__new__()`](#object.__new__ "object.__new__") is intended mainly to allow subclasses of immutable types (like ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
6ce8fc5d-39b1-5910-9658-42843f74703e
docs
python
python_datamodel
314
84
call it to ensure proper initialization of the base class part of the instance; for example: `super().__init__([args...])`. Because [`__new__()`](#object.__new__ "object.__new__") and [`__init__()`](#object.__init__ "object.__init__") work together in constructing objects ([`__new__()`](#object.__new__...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
6c245045-24af-505c-ab03-8d0d6287f29c
docs
python
python_datamodel
314
85
if any, must explicitly call it to ensure proper deletion of the base class part of the instance. It is possible (though not recommended!) for the [`__del__()`](#object.__del__ "object.__del__") method to postpone destruction of the instance by creating a new reference to it. This is called object ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
fba41c35-64b8-55c7-91a5-18ef99269523
docs
python
python_datamodel
314
86
`del x` doesn’t directly call `x.__del__()` — the former decrements the reference count for `x` by one, and the latter is only called when `x`’s reference count reaches zero. **CPython implementation detail:** It is possible for a reference cycle to prevent the reference count of an object from goi...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
4ca57144-a883-5310-9dca-8f2552854633
docs
python
python_datamodel
314
87
invoked, exceptions that occur during their execution are ignored, and a warning is printed to `sys.stderr` instead. In particular: * [`__del__()`](#object.__del__ "object.__del__") can be invoked when arbitrary code is being executed, including from any arbitrary thread. If [`__del__()`](#object.__d...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
64e05539-e037-5232-995e-409fec9d9414
docs
python
python_datamodel
314
88
no other references to such globals exist, this may help in assuring that imported modules are still available at the time when the [`__del__()`](#object.__del__ "object.__del__") method is called. object.\_\_repr\_\_(*self*)[¶](#object.__repr__ "Link to this definition") : Called by the [`repr()`]...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
628a0ac8-3fe0-5689-a2a9-92709e885f04
docs
python
python_datamodel
314
89
“informal” string representation of instances of that class is required. This is typically used for debugging, so it is important that the representation is information-rich and unambiguous. A default implementation is provided by the [`object`](../library/functions.html#object "object") class itself. ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
6e003d39-1022-5c91-8cb6-170857e5f32d
docs
python
python_datamodel
314
90
convenient or concise representation can be used. The default implementation defined by the built-in type [`object`](../library/functions.html#object "object") calls [`object.__repr__()`](#object.__repr__ "object.__repr__"). object.\_\_bytes\_\_(*self*)[¶](#object.__bytes__ "Link to this definition") : ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
29791524-1ddc-57f7-8214-caed4d3dc3cd
docs
python
python_datamodel
314
91
string representation of an object. The *format\_spec* argument is a string that contains a description of the formatting options desired. The interpretation of the *format\_spec* argument is up to the type implementing [`__format__()`](#object.__format__ "object.__format__"), however most classes will ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
aa669848-7c21-5c8f-b2bb-7d3479ebef57
docs
python
python_datamodel
314
92
Changed in version 3.7: `object.__format__(x, '')` is now equivalent to `str(x)` rather than `format(str(x), '')`. object.\_\_lt\_\_(*self*, *other*)[¶](#object.__lt__ "Link to this definition") object.\_\_le\_\_(*self*, *other*)[¶](#object.__le__ "Link to this definition") object.\_\_eq\_\_(*self*, *other*)...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
883728bd-bc54-5d16-9531-e89b83ede4d5
docs
python
python_datamodel
314
93
A rich comparison method may return the singleton [`NotImplemented`](../library/constants.html#NotImplemented "NotImplemented") if it does not implement the operation for a given pair of arguments. By convention, `False` and `True` are returned for a successful comparison. However, these methods can ret...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
2ed993c9-958d-5bb4-8846-8d4c6aaca3f9
docs
python
python_datamodel
314
94
`NotImplemented`. There are no other implied relationships among the comparison operators or default implementations; for example, the truth of `(x<y or x==y)` does not imply `x<=y`. To automatically generate ordering operations from a single root operation, see [`functools.total_ordering()`](../library...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
e1c8c6af-d561-592a-96ae-8f5271328219
docs
python
python_datamodel
314
95
some important notes on creating [hashable](../glossary.html#term-hashable) objects which support custom comparison operations and are usable as dictionary keys. There are no swapped-argument versions of these methods (to be used when the left argument does not support the operation but the right argum...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
ef801f3f-afc7-568d-9f3b-5afcfd83a3fa
docs
python
python_datamodel
314
96
When no appropriate method returns any value other than [`NotImplemented`](../library/constants.html#NotImplemented "NotImplemented"), the `==` and `!=` operators will fall back to `is` and `is not`, respectively. object.\_\_hash\_\_(*self*)[¶](#object.__hash__ "Link to this definition") : Called by built-in...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
cb85e9b1-7a9b-5bbb-ab21-a645d3d71e72
docs
python
python_datamodel
314
97
return hash((self.name, self.nick, self.color)) ``` Note [`hash()`](../library/functions.html#hash "hash") truncates the value returned from an object’s custom [`__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...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
bcdc3162-7f25-5f9c-acfd-e81a817ea2b9
docs
python
python_datamodel
314
98
[`__hash__()`](#object.__hash__ "object.__hash__"), its instances will not be usable as items in hashable collections. If a class defines mutable objects and implements an [`__eq__()`](#object.__eq__ "object.__eq__") method, it should not implement [`__hash__()`](#object.__hash__ "object.__hash__"), since t...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
c23c6e63-4419-5451-8791-df851b3c4894
docs
python
python_datamodel
314
99
A class that overrides [`__eq__()`](#object.__eq__ "object.__eq__") and does not define [`__hash__()`](#object.__hash__ "object.__hash__") will have its [`__hash__()`](#object.__hash__ "object.__hash__") implicitly set to `None`. When the [`__hash__()`](#object.__hash__ "object.__hash__") method of a class ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
20452589-d0dd-5ae3-8840-01786ee6724f
docs
python
python_datamodel
314
100
support, it should include `__hash__ = None` in the class definition. A class which defines its own [`__hash__()`](#object.__hash__ "object.__hash__") that explicitly raises a [`TypeError`](../library/exceptions.html#TypeError "TypeError") would be incorrectly identified as hashable by an `isinstance(ob...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
03afc10d-a4e1-5ac2-9818-8dfdc398b2ac
docs
python
python_datamodel
314
101
Python has never made guarantees about this ordering (and it typically varies between 32-bit and 64-bit builds). See also [`PYTHONHASHSEED`](../using/cmdline.html#envvar-PYTHONHASHSEED). Changed in version 3.3: Hash randomization is enabled by default. object.\_\_bool\_\_(*self*)[¶](#object.__bool__ ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
b34111b9-3ee7-5192-8f6f-ec44bea7aeb8
docs
python
python_datamodel
314
102
### 3.3.2. Customizing attribute access[¶](#customizing-attribute-access "Link to this heading") The following methods can be defined to customize the meaning of attribute access (use of, assignment to, or deletion of `x.name`) for class instances. object.\_\_getattr\_\_(*self*, *name*)[¶](#object.__getattr__ "Link t...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
f0f6e774-ae1f-5338-8ccd-e819960e4d12
docs
python
python_datamodel
314
103
attribute value or raise an [`AttributeError`](../library/exceptions.html#AttributeError "AttributeError") exception. The [`object`](../library/functions.html#object "object") class itself does not provide this method. Note that if the attribute is found through the normal mechanism, [`__getattr__()`](...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
ab57af7d-17db-58cc-af69-3bad9106f0bf
docs
python
python_datamodel
314
104
[`__getattribute__()`](#object.__getattribute__ "object.__getattribute__") method below for a way to actually get total control over attribute access. object.\_\_getattribute\_\_(*self*, *name*)[¶](#object.__getattribute__ "Link to this definition") : Called unconditionally to implement attribute accesses fo...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
a520c3a4-e8b6-5284-b1ab-66441ed8abab
docs
python
python_datamodel
314
105
method with the same name to access any attributes it needs, for example, `object.__getattribute__(self, name)`. Note This method may still be bypassed when looking up special methods as the result of implicit invocation via language syntax or [built-in functions](#builtin-functions). See ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
312a84b7-1f87-5c19-9c6b-1a7e8dcc64d0
docs
python
python_datamodel
314
106
call the base class method with the same name, for example, `object.__setattr__(self, name, value)`. For certain sensitive attribute assignments, raises an [auditing event](../library/sys.html#auditing) `object.__setattr__` with arguments `obj`, `name`, `value`. object.\_\_delattr\_\_(*self*, *nam...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
f9f9eb16-596a-5e63-ba09-caa70616450b
docs
python
python_datamodel
314
107
returned. [`dir()`](../library/functions.html#dir "dir") converts the returned iterable to a list and sorts it. #### 3.3.2.1. Customizing module attribute access[¶](#customizing-module-attribute-access "Link to this heading") module.\_\_getattr\_\_()[¶](#module.__getattr__ "Link to this definition") module.\_\_d...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
b87fdf5a-750a-56c5-9e1e-d2baaada8914
docs
python
python_datamodel
314
108
the module `__dict__` before raising an [`AttributeError`](../library/exceptions.html#AttributeError "AttributeError"). If found, it is called with the attribute name and the result is returned. The `__dir__` function should accept no arguments, and return an iterable of strings that represents the names accessible on...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
7ff42e6d-0b67-5647-91d1-9864968320bf
docs
python
python_datamodel
314
109
super().__setattr__(attr, value) sys.modules[__name__].__class__ = VerboseModule ``` Note Defining module `__getattr__` and setting module `__class__` only affect lookups made using the attribute access syntax – directly accessing the module globals (whether by code within the module, or via a reference to t...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
aeeccc68-74e6-5a39-a201-6f4a29536ddb
docs
python
python_datamodel
314
110
dictionary for one of its parents). In the examples below, “the attribute” refers to the attribute whose name is the key of the property in the owner class’ [`__dict__`](#object.__dict__ "object.__dict__"). The [`object`](../library/functions.html#object "object") class itself does not implement any of these protocols....
large_dataset/raw/docs/python/datamodel/datamodel_314.md
35ed8b71-ae54-5c0e-9f12-b3893ca8cfc0
docs
python
python_datamodel
314
111
[**PEP 252**](https://peps.python.org/pep-0252/) specifies that [`__get__()`](#object.__get__ "object.__get__") is callable with one or two arguments. Python’s own built-in descriptors support this specification; however, it is likely that some third-party tools have descriptors that require both argume...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
0d42bfa7-1ef2-5eff-98c0-3b749bc30d04
docs
python
python_datamodel
314
112
object.\_\_delete\_\_(*self*, *instance*)[¶](#object.__delete__ "Link to this definition") : Called to delete the attribute on an instance *instance* of the owner class. Instances of descriptors may also have the `__objclass__` attribute present: object.\_\_objclass\_\_[¶](#object.__objclass__ "Link to this definit...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
450716e0-1b1e-55a5-b4b8-57a8d5ca0059
docs
python
python_datamodel
314
113
#### 3.3.2.3. Invoking Descriptors[¶](#invoking-descriptors "Link to this heading") In general, a descriptor is an object attribute with “binding behavior”, one whose attribute access has been overridden by methods in the descriptor protocol: [`__get__()`](#object.__get__ "object.__get__"), [`__set__()`](#object.__set...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
28c17f48-c320-5913-be41-11ed0dad9a92
docs
python
python_datamodel
314
114
descriptor methods were defined and how they were called. The starting point for descriptor invocation is a binding, `a.x`. How the arguments are assembled depends on `a`: Direct Call : The simplest and least common call is when user code directly invokes a descriptor method: `x.__get__(a)`. Instance Binding :...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
a883e813-ab9c-57df-9549-d658c7b515c0
docs
python
python_datamodel
314
115
of [`__get__()`](#object.__get__ "object.__get__"), [`__set__()`](#object.__set__ "object.__set__") and [`__delete__()`](#object.__delete__ "object.__delete__"). If it does not define `__get__()`, then accessing the attribute will return the descriptor object itself unless there is a value in the object’s instance dict...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
e5a77e55-6c4d-51e3-a62b-7a347fc2faec
docs
python
python_datamodel
314
116
implemented as non-data descriptors. Accordingly, instances can redefine and override methods. This allows individual instances to acquire behaviors that differ from other instances of the same class. The [`property()`](../library/functions.html#property "property") function is implemented as a data descriptor. Accord...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
bd3f753c-b229-5095-bcde-4a14837bc014
docs
python
python_datamodel
314
117
strings with variable names used by instances. *\_\_slots\_\_* reserves space for the declared variables and prevents the automatic creation of [`__dict__`](#object.__dict__ "object.__dict__") and *\_\_weakref\_\_* for each instance. Notes on using *\_\_slots\_\_*: * When inheriting from a class witho...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
ab0fa2cf-8b7f-5308-9fb6-8131b6f013c9
docs
python
python_datamodel
314
118
*\_\_slots\_\_* do not support [`weak references`](../library/weakref.html#module-weakref "weakref: Support for weak references and weak dictionaries.") to its instances. If weak reference support is needed, then add `'__weakref__'` to the sequence of strings in the *\_\_slots\_\_* declaration. * *\_\_slots\_\_...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
4cab31d0-979c-56f4-bc1e-611ce6440f79
docs
python
python_datamodel
314
119
* If a class defines a slot also defined in a base class, the instance variable defined by the base class slot is inaccessible (except by retrieving its descriptor directly from the base class). This renders the meaning of the program undefined. In the future, a check may be added to prevent this. * [`TypeError`]...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
c7631ac5-8584-52f2-ab94-f26e35a4e877
docs
python
python_datamodel
314
120
to provide per-attribute docstrings that will be recognised by [`inspect.getdoc()`](../library/inspect.html#inspect.getdoc "inspect.getdoc") and displayed in the output of [`help()`](../library/functions.html#help "help"). * [`__class__`](#object.__class__ "object.__class__") assignment works only if both classes h...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
17bbcbf4-866a-55a9-905c-0832e0a8d292
docs
python
python_datamodel
314
121
### 3.3.3. Customizing class creation[¶](#customizing-class-creation "Link to this heading") Whenever a class inherits from another class, [`__init_subclass__()`](#object.__init_subclass__ "object.__init_subclass__") is called on the parent class. This way, it is possible to write classes which change the behavior of ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
23f12cac-e50e-53cc-8cdd-acd401775fa8
docs
python
python_datamodel
314
122
other classes using `__init_subclass__`, one should take out the needed keyword arguments and pass the others over to the base class, as in: ```None class Philosopher: def __init_subclass__(cls, /, default_name, **kwargs): super().__init_subclass__(**kwargs) cls.defa...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
355ca6c7-1872-5d63-b641-3e8abd07bf72
docs
python
python_datamodel
314
123
object.\_\_set\_name\_\_(*self*, *owner*, *name*)[¶](#object.__set_name__ "Link to this definition") : Automatically called at the time the owning class *owner* is created. The object has been assigned to *name* in that class: ```None class A: x = C() # Automatically calls: x.__set_name__(A, 'x'...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
379bea96-fd26-5b03-a970-621cd5d6d77e
docs
python
python_datamodel
314
124
#### 3.3.3.1. Metaclasses[¶](#metaclasses "Link to this heading") By default, classes are constructed using [`type()`](../library/functions.html#type "type"). The class body is executed in a new namespace and the class name is bound locally to the result of `type(name, bases, namespace)`. The class creation process c...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
2a46a7a0-a580-5adf-a8f0-042e69a83b0f
docs
python
python_datamodel
314
125
* the class object is created. #### 3.3.3.2. Resolving MRO entries[¶](#resolving-mro-entries "Link to this heading") object.\_\_mro\_entries\_\_(*self*, *bases*)[¶](#object.__mro_entries__ "Link to this definition") : If a base that appears in a class definition is not an instance of [`type`](../library/functio...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
5e1072f8-e2e6-5831-88ef-a96c299d5b6f
docs
python
python_datamodel
314
126
[`types.get_original_bases()`](../library/types.html#types.get_original_bases "types.get_original_bases") : Retrieve a class’s “original bases” prior to modifications by [`__mro_entries__()`](#object.__mro_entries__ "object.__mro_entries__"). [**PEP 560**](https://peps.python.org/pep-0560/) : Core support for ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
0f91ff28-4e95-5a9b-bd40-c0198b3d15ee
docs
python
python_datamodel
314
127
The most derived metaclass is selected from the explicitly specified metaclass (if any) and the metaclasses (i.e. `type(cls)`) of all specified base classes. The most derived metaclass is one which is a subtype of *all* of these candidate metaclasses. If none of the candidate metaclasses meets that criterion, then the ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
b1411540-e2da-59fe-b1eb-49c8c1225d46
docs
python
python_datamodel
314
128
the final class object is created the namespace is copied into a new `dict`. If the metaclass has no `__prepare__` attribute, then the class namespace is initialised as an empty ordered mapping. See also [**PEP 3115**](https://peps.python.org/pep-3115/) - Metaclasses in Python 3000 : Introduced the `__prepare__` n...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
ef7ba1c3-9f28-5069-9167-87f066b2000f
docs
python
python_datamodel
314
129
class methods, or through the implicit lexically scoped `__class__` reference described in the next section. #### 3.3.3.6. Creating the class object[¶](#creating-the-class-object "Link to this heading") Once the class namespace has been populated by executing the class body, the class object is created by calling `me...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
c0fef70e-6625-5002-b9b4-dd962eaf58e3
docs
python
python_datamodel
314
130
**CPython implementation detail:** In CPython 3.6 and later, the `__class__` cell is passed to the metaclass as a `__classcell__` entry in the class namespace. If present, this must be propagated up to the `type.__new__` call in order for the class to be initialised correctly. Failing to do so will result in a [`Runtim...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
83c0c6b8-d3c8-5179-98a5-b97acd45fc78
docs
python
python_datamodel
314
131
3. The [`__init_subclass__()`](#object.__init_subclass__ "object.__init_subclass__") hook is called on the immediate parent of the new class in its method resolution order. After the class object is created, it is passed to the class decorators included in the class definition (if any) and the resulting object is b...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
f2eb3866-6c19-53bd-8a47-b8ed5ce713ca
docs
python
python_datamodel
314
132
#### 3.3.3.7. Uses for metaclasses[¶](#uses-for-metaclasses "Link to this heading") The potential uses for metaclasses are boundless. Some ideas that have been explored include enum, logging, interface checking, automatic delegation, automatic property creation, proxies, frameworks, and automatic resource locking/sync...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
6eeb2473-7358-5999-b7bb-443f98975186
docs
python
python_datamodel
314
133
type.\_\_instancecheck\_\_(*self*, *instance*)[¶](#type.__instancecheck__ "Link to this definition") : Return true if *instance* should be considered a (direct or indirect) instance of *class*. If defined, called to implement `isinstance(instance, class)`. type.\_\_subclasscheck\_\_(*self*, *subclass*)[¶](#t...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
818ef5de-2e82-5f4a-a26a-b770ace247bf
docs
python
python_datamodel
314
134
[`issubclass()`](../library/functions.html#issubclass "issubclass") behavior through [`__instancecheck__()`](#type.__instancecheck__ "type.__instancecheck__") and [`__subclasscheck__()`](#type.__subclasscheck__ "type.__subclasscheck__"), with motivation for this functionality in the context of adding Abstra...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
73f50b7b-c8dc-5c72-b0df-7d0300910040
docs
python
python_datamodel
314
135
: Introducing Python’s framework for type annotations [Generic Alias Types](../library/stdtypes.html#types-genericalias) : Documentation for objects representing parameterized generic classes [Generics](../library/typing.html#generics), [user-defined generics](../library/typing.html#user-defined-generics) and [`t...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
34939e8a-b9cf-50f8-b87e-748412710e49
docs
python
python_datamodel
314
136
[`@classmethod`](../library/functions.html#classmethod "classmethod") when it is defined. #### 3.3.5.1. The purpose of *\_\_class\_getitem\_\_*[¶](#the-purpose-of-class-getitem "Link to this heading") The purpose of [`__class_getitem__()`](#object.__class_getitem__ "object.__class_getitem__") is to allow runtime ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
ecd395ce-ae8c-58d0-84db-05d4002da5ab
docs
python
python_datamodel
314
137
outside of the standard library may not be understood by third-party type-checkers such as mypy. Using `__class_getitem__()` on any class for purposes other than type hinting is discouraged. #### 3.3.5.2. *\_\_class\_getitem\_\_* versus *\_\_getitem\_\_*[¶](#class-getitem-versus-getitem "Link to this heading") Usuall...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
b7ba6af6-cd9e-5066-902b-a4e99a4f4407
docs
python
python_datamodel
314
138
[`__getitem__()`](#object.__getitem__ "object.__getitem__") or [`__class_getitem__()`](#object.__class_getitem__ "object.__class_getitem__") should be called: ```None from inspect import isclass def subscribe(obj, x): """Return the result of the expression 'obj[x]'""" class_of_obj = type(obj) # If the c...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
6be1d9e9-202b-59a4-9df9-cc2ca8a0caf0
docs
python
python_datamodel
314
139
[`type`](../library/functions.html#type "type") class as their metaclass. [`type`](../library/functions.html#type "type") does not define [`__getitem__()`](#object.__getitem__ "object.__getitem__"), meaning that expressions such as `list[int]`, `dict[str, float]` and `tuple[str, bytes]` all result in [`__class_getitem_...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
33e13daa-d8fb-5fa0-961e-4f3ea80d227a
docs
python
python_datamodel
314
140
behaviour. An example of this can be found in the [`enum`](../library/enum.html#module-enum "enum: Implementation of an enumeration class.") module: ```None >>> from enum import Enum >>> class Menu(Enum): ... """A breakfast menu""" ... SPAM = 'spam' ... BACON = 'bacon' ... >>> # Enum classes have a custom ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
c6369bbd-62f1-5b47-8b43-bb5b27ba0b8b
docs
python
python_datamodel
314
141
### 3.3.6. Emulating callable objects[¶](#emulating-callable-objects "Link to this heading") object.\_\_call\_\_(*self*[, *args...*])[¶](#object.__call__ "Link to this definition") : Called when the instance is “called” as a function; if this method is defined, `x(arg1, arg2, ...)` roughly translates to `type(x)...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
5547a3d8-c278-505d-9b78-01de16cdc465
docs
python
python_datamodel
314
142
but can represent other containers as well. The first set of methods is used either to emulate a sequence or to emulate a mapping; the difference is that for a sequence, the allowable keys should be the integers *k* for which `0 <= k < N` where *N* is the length of the sequence, or [`slice`](../library/functions.html#s...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
71cd0da3-36e7-5b6a-8910-ff11935bdd18
docs
python
python_datamodel
314
143
[abstract base class](../glossary.html#term-abstract-base-class) to help create those methods from a base set of [`__getitem__()`](#object.__getitem__ "object.__getitem__"), [`__setitem__()`](#object.__setitem__ "object.__setitem__"), [`__delitem__()`](#object.__delitem__ "object.__delitem__"), and `keys()`. Mutable s...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
00eb409b-7ecb-5d54-8dee-cbac3302cbd9
docs
python
python_datamodel
314
144
like Python standard [`list`](../library/stdtypes.html#list "list") objects. Finally, sequence types should implement addition (meaning concatenation) and multiplication (meaning repetition) by defining the methods [`__add__()`](#object.__add__ "object.__add__"), [`__radd__()`](#object.__radd__ "object.__radd__"), [`__...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
6d2acbaf-5ac3-561e-9b96-c9b4f7f53d19
docs
python
python_datamodel
314
145
sequences implement the [`__iter__()`](#object.__iter__ "object.__iter__") method to allow efficient iteration through the container; for mappings, `__iter__()` should iterate through the object’s keys; for sequences, it should iterate through the values. object.\_\_len\_\_(*self*)[¶](#object.__len__ "Link to this def...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
e81d5e22-e05e-5023-ac8c-45bf2e0e8c56
docs
python
python_datamodel
314
146
[`len()`](../library/functions.html#len "len")) may raise [`OverflowError`](../library/exceptions.html#OverflowError "OverflowError"). To prevent raising `OverflowError` by truth value testing, an object must define a [`__bool__()`](#object.__bool__ "object.__bool__") method. object.\_\_length\_hint\_\_(*s...
large_dataset/raw/docs/python/datamodel/datamodel_314.md
76d4c845-770b-5033-95ae-38bd5fb27d7a
docs
python
python_datamodel
314
147
Slicing is done exclusively with the following three methods. A call like ```None a[1:2] = b ``` is translated to ```None a[slice(1, 2, None)] = b ``` and so forth. Missing slice items are always filled in with `None`. object.\_\_getitem\_\_(*self*, *subscript*)[¶](#object.__getitem__ "Link to this definition") : ...
large_dataset/raw/docs/python/datamodel/datamodel_314.md