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 |
|---|---|---|---|---|---|---|---|
26ab6245-dc4b-5154-92a2-ede74ab5ea1a | docs | python | python_datamodel | 313 | 28 | ([`__func__`](#method.__func__ "method.__func__")) is called, inserting the class instance
([`__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 t... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
778b7bf2-10e0-5c1b-9131-214e2c008caa | docs | python | python_datamodel | 313 | 29 | #### 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_313.md |
ab310f91-60ab-5b05-85a1-5aa168a82b6e | docs | python | python_datamodel | 313 | 30 | #### 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_313.md |
101ab5f0-d3ab-5c9b-970e-a9a4fb4e0239 | docs | python | python_datamodel | 313 | 31 | [`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_313.md |
6bd4e50b-d274-5de7-b298-eb7973c0b91f | docs | python | python_datamodel | 313 | 32 | 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_313.md |
91ae1260-2b4d-51d1-b63d-b692eda9fbb3 | docs | python | python_datamodel | 313 | 33 | #### 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_313.md |
4ab409f5-62b8-5531-8a1c-8efdd301fb7f | docs | python | python_datamodel | 313 | 34 | #### 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_313.md |
9517efa3-e8d6-519c-9d1b-57090bc86b6d | docs | python | python_datamodel | 313 | 35 | 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_313.md |
880b8ae2-265a-53ec-86ac-3f7b87fcd25b | docs | python | python_datamodel | 313 | 36 | 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_313.md |
eb7d4fe2-1cc6-5db1-acdb-fafc614febc8 | docs | python | python_datamodel | 313 | 37 | >>> 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_313.md |
7e9644cc-9206-5c69-92f1-9d41117ff185 | docs | python | python_datamodel | 313 | 38 | 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_313.md |
ab911025-c627-5f0b-99d0-82bc068f6084 | docs | python | python_datamodel | 313 | 39 | 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_313.md |
8c3079bf-3074-56c4-bd24-a4e224e22f0c | docs | python | python_datamodel | 313 | 40 | [`__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_313.md |
b92c946c-fd32-5c9a-a8fb-a41a47e7e332 | docs | python | python_datamodel | 313 | 41 | 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_313.md |
3095cdb1-732a-582f-839d-9885edbd1621 | docs | python | python_datamodel | 313 | 42 | 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_313.md |
23184e35-8c3b-57e0-a4d6-fb0d6d85e307 | docs | python | python_datamodel | 313 | 43 | [`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_313.md |
3546c51a-2f05-50b3-9bdb-f967a2b33cf7 | docs | python | python_datamodel | 313 | 44 | 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_313.md |
03e8f6d6-9fb9-5511-b0f2-ea552f15d73d | docs | python | python_datamodel | 313 | 45 | [`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_313.md |
9e2b6765-582f-5b93-aea5-63027a03a456 | docs | python | python_datamodel | 313 | 46 | : A dictionary containing
[variable annotations](../glossary.html#term-variable-annotation) collected during module
body execution. For best practices on working with [`__annotations__`](#module.__annotations__ "module.__annotations__"),
please see [Annotations Best Practices](../howto/annotations.html#an... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
33422d24-2aec-53a3-8a4e-5a258496d081 | docs | python | python_datamodel | 313 | 47 | dictionary still has live references. To avoid this, copy the dictionary
or keep the module around while using its dictionary directly.
### 3.2.10. Custom classes[¶](#custom-classes "Link to this heading")
Custom class types are typically created by class definitions (see section
[Class definitions](compound_... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
9b128947-ab6f-51e4-8af4-44be677c58e5 | docs | python | python_datamodel | 313 | 48 | [The Python 2.3 Method Resolution Order](../howto/mro.html#python-2-3-mro).
When a class attribute reference (for class `C`, say) would yield a
class method object, it is transformed into an instance method object whose
[`__self__`](#method.__self__ "method.__self__") attribute is `C`.
When it would yield a [`staticme... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
3b84ffab-aa10-5c4e-b2bb-0a6db0af3879 | docs | python | python_datamodel | 313 | 49 | #### 3.2.10.1. Special attributes[¶](#special-attributes "Link to this heading")
| Attribute | Meaning |
| --- | --- |
| type.\_\_name\_\_[¶](#type.__name__ "Link to this definition") | The class’s name. See also: [`__name__ attributes`](../library/stdtypes.html#definition.__name__ "definition.__name__"). |
| type.\_\... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
200b95c0-d834-5357-aaca-c57ee4e02630 | docs | python | python_datamodel | 313 | 50 | | type.\_\_bases\_\_[¶](#type.__bases__ "Link to this definition") | A [`tuple`](../library/stdtypes.html#tuple "tuple") containing the class’s bases. In most cases, for a class defined as `class X(A, B, C)`, `X.__bases__` will be exactly equal to `(A, B, C)`. |
| type.\_\_base\_\_[¶](#type.__base__ "Link to this defin... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
352d3727-2a66-5bd8-a3ce-9771fb147084 | docs | python | python_datamodel | 313 | 51 | | type.\_\_annotations\_\_[¶](#type.__annotations__ "Link to this definition") | A dictionary containing [variable annotations](../glossary.html#term-variable-annotation) collected during class body execution. For best practices on working with `__annotations__`, please see [Annotations Best Practices](../howto/annotat... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
dfe2ab98-9e06-5dbd-8172-ca06883c02d8 | docs | python | python_datamodel | 313 | 52 | | type.\_\_static\_attributes\_\_[¶](#type.__static_attributes__ "Link to this definition") | A [`tuple`](../library/stdtypes.html#tuple "tuple") containing names of attributes of this class which are assigned through `self.X` from any function in its body. Added in version 3.13. |
| type.\_\_firstlineno\_\_[¶](#type.... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
150097a8-45a4-5562-8bb1-9d4c4f185f5a | docs | python | python_datamodel | 313 | 53 | type.mro()[¶](#type.mro "Link to this definition")
: This method can be overridden by a metaclass to customize the method
resolution order for its instances. It is called at class instantiation,
and its result is stored in [`__mro__`](#type.__mro__ "type.__mro__").
type.\_\_subclasses\_\_()[¶](#type.__subcla... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
7e387196-b97a-5c82-aa09-abc30a0d7a38 | docs | python | python_datamodel | 313 | 54 | continues with the class attributes. If a class attribute is found that is a
user-defined function object, it is transformed into an instance method
object whose [`__self__`](#method.__self__ "method.__self__") attribute is the instance. Static method and
class method objects are also transformed; see above under “Clas... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
022dfbb6-db0e-5b5b-8393-a434563cda59 | docs | python | python_datamodel | 313 | 55 | [`__delattr__()`](#object.__delattr__ "object.__delattr__") method, this is called instead of updating the instance
dictionary directly.
Class instances can pretend to be numbers, sequences, or mappings if they have
methods with certain special names. See section [Special method names](#specialnames).
#### 3.2.11.1. ... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
61b4d1a3-9377-500c-b66c-2224da124179 | docs | python | python_datamodel | 313 | 56 | available to create file objects: the [`open()`](../library/functions.html#open "open") built-in function, and
also [`os.popen()`](../library/os.html#os.popen "os.popen"), [`os.fdopen()`](../library/os.html#os.fdopen "os.fdopen"), and the
[`makefile()`](../library/socket.html#socket.socket.makefile "socket.socket.makef... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
fb92ce8b-cfba-5fb2-ad28-0ab7d5795047 | docs | python | python_datamodel | 313 | 57 | #### 3.2.13.1. Code objects[¶](#code-objects "Link to this heading")
Code objects represent *byte-compiled* executable Python code, or [bytecode](../glossary.html#term-bytecode).
The difference between a code object and a function object is that the function
object contains an explicit reference to the function’s glob... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
6864908c-c7e8-5d5c-b39b-09e31ef197b9 | docs | python | python_datamodel | 313 | 58 | | 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_313.md |
19d67cfd-82f6-51f9-b8c7-e77dca6c5960 | docs | python | python_datamodel | 313 | 59 | | 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_313.md |
29a1bff4-15a3-5bc4-9c5f-e2fecbf4ff19 | docs | python | python_datamodel | 313 | 60 | | 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_313.md |
b6fed45f-a299-544f-a54e-02e221c42e04 | docs | python | python_datamodel | 313 | 61 | | 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_313.md |
4d95653c-e34c-5edf-99b8-11745fb15507 | docs | python | python_datamodel | 313 | 62 | 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_313.md |
7d55a4af-b926-5876-90d9-090af9705078 | docs | python | python_datamodel | 313 | 63 | ##### 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_313.md |
4136d425-d4f2-5927-9429-f5d69ccd49e5 | docs | python | python_datamodel | 313 | 64 | * 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_313.md |
9db1e586-503f-5fbe-9930-1407c30bae3c | docs | python | python_datamodel | 313 | 65 | [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_313.md |
54b341ee-5156-54fa-9f58-3c19e97fb480 | docs | python | python_datamodel | 313 | 66 | 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_313.md |
68897e5e-3a34-5b5f-8a7e-4898b92d6cfe | docs | python | python_datamodel | 313 | 67 | 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_313.md |
a983f195-3eaa-5eac-aec8-58a9d68024e9 | docs | python | python_datamodel | 313 | 68 | | 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_313.md |
e61781db-9172-58f1-a2f3-3d779f410654 | docs | python | python_datamodel | 313 | 69 | ##### 3.2.13.2.2. Special writable attributes[¶](#index-67 "Link to this heading")
| | |
| --- | --- |
| frame.f\_trace[¶](#frame.f_trace "Link to this definition") | If not `None`, this is a function called for various events during code execution (this is used by debuggers). Normally an event is triggered for each... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
300bc8f5-f280-5e38-a5a2-f5619d308a11 | docs | python | python_datamodel | 313 | 70 | | frame.f\_lineno[¶](#frame.f_lineno "Link to this definition") | The current line number of the frame – writing to this from within a trace function jumps to the given line (only for the bottom-most frame). A debugger can implement a Jump command (aka Set Next Statement) by writing to this attribute. |
##### 3.2.13.2... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
a4d861c4-842a-55da-9a7c-773e3d6af3fc | docs | python | python_datamodel | 313 | 71 | [`RuntimeError`](../library/exceptions.html#RuntimeError "RuntimeError") is raised if the frame is currently executing
or suspended.
Added in version 3.4.
Changed in version 3.13: Attempting to clear a suspended frame raises [`RuntimeError`](../library/exceptions.html#RuntimeError "RuntimeError")
... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
15b76359-e333-55cf-8f84-cd0debe3b8ca | docs | python | python_datamodel | 313 | 72 | inserted in front of the current traceback. When an exception handler is
entered, the stack trace is made available to the program. (See section
[The try statement](compound_stmts.html#try).) It is accessible as the third item of the
tuple returned by [`sys.exc_info()`](../library/sys.html#sys.exc_info "sys.exc_info"),... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
4f7a55c9-3de2-5605-94ff-8cb983098887 | docs | python | python_datamodel | 313 | 73 | | traceback.tb\_frame[¶](#traceback.tb_frame "Link to this definition") | Points to the execution [frame](#frame-objects) of the current level. Accessing this attribute raises an [auditing event](../library/sys.html#auditing) `object.__getattr__` with arguments `obj` and `"tb_frame"`. |
| traceback.tb\_lineno[¶](#trac... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
bc95bac1-39fd-5cae-b814-243023f86bcb | docs | python | python_datamodel | 313 | 74 | stack trace (towards the frame where the exception occurred), or `None` if
there is no next level.
Changed in version 3.7: This attribute is now writable
#### 3.2.13.4. Slice objects[¶](#slice-objects "Link to this heading")
Slice objects are used to represent slices for
[`__getitem__()`](#object.__getit... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
8d076351-b508-5229-82f6-50263bf550ae | docs | python | python_datamodel | 313 | 75 | information about the slice that the slice object would describe if
applied to a sequence of *length* items. It returns a tuple of three
integers; respectively these are the *start* and *stop* indices and the
*step* or stride length of the slice. Missing or out-of-bounds indices
are handled in a man... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
ee057159-b15c-5294-b7fd-4e53b166e047 | docs | python | python_datamodel | 313 | 76 | #### 3.2.13.6. Class method objects[¶](#class-method-objects "Link to this heading")
A class method object, like a static method object, is a wrapper around another
object that alters the way in which that object is retrieved from classes and
class instances. The behaviour of class method objects upon such retrieval i... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
6910465b-0cfe-51b4-86a4-7730494b5c62 | docs | python | python_datamodel | 313 | 77 | and `x` is an instance of this class, then `x[i]` is roughly equivalent
to `type(x).__getitem__(x, i)`. Except where mentioned, attempts to execute an
operation raise an exception when no appropriate method is defined (typically
[`AttributeError`](../library/exceptions.html#AttributeError "AttributeError") or [`TypeErr... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
b0e651f7-14a1-59cf-ab6d-eefca9113d06 | docs | python | python_datamodel | 313 | 78 | object being modelled. For example, some sequences may work well with retrieval
of individual elements, but extracting a slice may not make sense. (One example
of this is the `NodeList` interface in the W3C’s Document
Object Model.)
### 3.3.1. Basic customization[¶](#basic-customization "Link to this heading")
object... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
5621eb07-5a44-5be4-9743-6ed3f793eeb8 | docs | python | python_datamodel | 313 | 79 | superclass’s [`__new__()`](#object.__new__ "object.__new__") method using `super().__new__(cls[, ...])`
with appropriate arguments and then modifying the newly created instance
as necessary before returning it.
If [`__new__()`](#object.__new__ "object.__new__") is invoked during object construction and... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
4758315c-8476-5b46-9475-887ea7c9c42e | docs | python | python_datamodel | 313 | 80 | overridden in custom metaclasses in order to customize class creation.
object.\_\_init\_\_(*self*[, *...*])[¶](#object.__init__ "Link to this definition")
: Called after the instance has been created (by [`__new__()`](#object.__new__ "object.__new__")), but before
it is returned to the caller. The arguments ... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
3cc27845-c25e-5dae-94cc-9c9c72bf7b88 | docs | python | python_datamodel | 313 | 81 | no non-`None` value may be returned by [`__init__()`](#object.__init__ "object.__init__"); doing so will
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 abou... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
d56a8120-d884-5a30-9641-534ce3530f78 | docs | python | python_datamodel | 313 | 82 | whether [`__del__()`](#object.__del__ "object.__del__") is called a second time when a resurrected object
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 a... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
44b6cf13-0e31-5d40-8501-c6821c98221d | docs | python | python_datamodel | 313 | 83 | later detected and deleted by the [cyclic garbage collector](../glossary.html#term-garbage-collection). A common cause of reference cycles is when
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 l... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
0d8cf725-7a4a-5ce9-9046-7bb71e5d1e32 | docs | python | python_datamodel | 313 | 84 | a lock or invoke any other blocking resource, it may deadlock as
the resource may already be taken by the code that gets interrupted
to execute [`__del__()`](#object.__del__ "object.__del__").
* [`__del__()`](#object.__del__ "object.__del__") can be executed during interpreter shutdown. As a
... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
bf87e7b1-0b85-51b6-9414-e23900797d90 | docs | python | python_datamodel | 313 | 85 | representation of an object. If at all possible, this should look like a
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 re... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
6302a709-1d09-55ce-b1e4-3041d0668c9d | docs | python | python_datamodel | 313 | 86 | : 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_313.md |
7d245866-9290-521f-a72a-ff3493c0ea30 | docs | python | python_datamodel | 313 | 87 | : 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_313.md |
9c9ade36-d798-52dc-8a3f-24b1a66de112 | docs | python | python_datamodel | 313 | 88 | 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_313.md |
23dff4b5-c2f8-51bd-b82e-c28113889a6f | docs | python | python_datamodel | 313 | 89 | 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_313.md |
654eb942-b943-5645-80c8-2d4cdd1d6abc | docs | python | python_datamodel | 313 | 90 | 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_313.md |
a7b9dc83-c709-53de-8993-ed466b328019 | docs | python | python_datamodel | 313 | 91 | 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_313.md |
58b90cc7-8e96-5d28-a7f6-42391e7fe3b0 | docs | python | python_datamodel | 313 | 92 | 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_313.md |
32c097e7-e391-5a9a-a411-736c77e9ee78 | docs | python | python_datamodel | 313 | 93 | 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_313.md |
6f291952-4ea3-5a75-bea5-77207bab5b34 | docs | python | python_datamodel | 313 | 94 | [`__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_313.md |
b0a292ee-c477-5acd-a421-ffbec4013b59 | docs | python | python_datamodel | 313 | 95 | [`__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_313.md |
658ed05a-3085-5294-91bf-415636900d80 | docs | python | python_datamodel | 313 | 96 | [`__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_313.md |
64ea0ce3-283d-5d8b-a328-6157e3e24f0a | docs | python | python_datamodel | 313 | 97 | 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_313.md |
90375d16-1cd1-59cf-bf53-e39d46f3f0e8 | docs | python | python_datamodel | 313 | 98 | 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_313.md |
1a3bcc55-e5a3-58e1-b905-b6bd9430e097 | docs | python | python_datamodel | 313 | 99 | : 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_313.md |
a30f99a0-4d6b-51ad-98ce-f523cc84b11f | docs | python | python_datamodel | 313 | 100 | [`__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_313.md |
fa37e748-86b8-5726-9c34-5dbd7aee0483 | docs | python | python_datamodel | 313 | 101 | 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_313.md |
172ebaff-bf79-5937-a018-c7d7e582c925 | docs | python | python_datamodel | 313 | 102 | 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_313.md |
838cac16-999a-5bad-ae5a-90e559f92fc4 | docs | python | python_datamodel | 313 | 103 | : 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_313.md |
cc0c2954-2b26-5025-93a8-5d1a5b8ab8c8 | docs | python | python_datamodel | 313 | 104 | 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_313.md |
53ab2456-b35f-5603-a9bc-53d05f95005d | docs | python | python_datamodel | 313 | 105 | 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_313.md |
02c06d51-ad92-5b22-af24-e323e8ae7554 | docs | python | python_datamodel | 313 | 106 | [**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_313.md |
24308114-a091-575a-bb99-ec982c65143c | docs | python | python_datamodel | 313 | 107 | 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_313.md |
b0d982b2-5ce8-5477-8900-aeb5c31647ac | docs | python | python_datamodel | 313 | 108 | : 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_313.md |
73484083-d9f5-53bf-903a-3f698086e31b | docs | python | python_datamodel | 313 | 109 | 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_313.md |
37db0d3f-f0aa-5be0-9449-bcb906d13278 | docs | python | python_datamodel | 313 | 110 | 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_313.md |
923c5b6a-57cf-594f-9cbe-c81f0ccd221c | docs | python | python_datamodel | 313 | 111 | `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_313.md |
db68fd3c-6f58-5527-a78a-660ff1d38459 | docs | python | python_datamodel | 313 | 112 | 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_313.md |
f11b0f3b-fca8-5c10-ac22-486cbd0c0000 | docs | python | python_datamodel | 313 | 113 | 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_313.md |
d14eb74c-d5b3-53e9-9791-1b3b58d21d32 | docs | python | python_datamodel | 313 | 114 | 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_313.md |
b7619863-86e8-5bbd-b8ee-e2cfd8ddb429 | docs | python | python_datamodel | 313 | 115 | 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_313.md |
c1425aa6-1bb9-5b4a-8613-79cc00645597 | docs | python | python_datamodel | 313 | 116 | [`int`](../library/functions.html#int "int"), [`bytes`](../library/stdtypes.html#bytes "bytes"), and [`tuple`](../library/stdtypes.html#tuple "tuple").
* Any non-string [iterable](../glossary.html#term-iterable) may be assigned to *\_\_slots\_\_*.
* If a [`dictionary`](../library/stdtypes.html#dict "dict") is used to... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
521106bf-0d32-54b6-aad5-40a2786f19d8 | docs | python | python_datamodel | 313 | 117 | (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#term-descriptor) is
created for each
of the iterator’s values. Ho... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
cf4212e0-ebf3-5137-93cb-77e405b598bc | docs | python | python_datamodel | 313 | 118 | *classmethod* object.\_\_init\_subclass\_\_(*cls*)[¶](#object.__init_subclass__ "Link to this definition")
: This method is called whenever the containing class is subclassed.
*cls* is then the new subclass. If defined as a normal instance method,
this method is implicitly converted to a class method.
Ke... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
62b44726-6ce2-5e5b-b41a-18ad38fbd793 | docs | python | python_datamodel | 313 | 119 |
The metaclass hint `metaclass` is consumed by the rest of the type
machinery, and is never passed to `__init_subclass__` implementations.
The actual metaclass (rather than the explicit hint) can be accessed as
`type(cls)`.
Added in version 3.6.
When a class is created, `type.__new__()` scans the ... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
21b757a3-f764-5811-b311-7ee2d10242a6 | docs | python | python_datamodel | 313 | 120 | If needed, [`__set_name__()`](#object.__set_name__ "object.__set_name__") can be called directly:
```None
class A:
pass
c = C()
A.x = c # The hook is not called
c.__set_name__(A, 'x') # Manually invoke the hook
```
See [Creating the class object](#class-objec... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
c7702693-646a-53fc-8c01-6ea5acf0efab | docs | python | python_datamodel | 313 | 121 | class MySubclass(MyClass):
pass
```
Any other keyword arguments that are specified in the class definition are
passed through to all metaclass operations described below.
When a class definition is executed, the following steps occur:
* MRO entries are resolved;
* the appropriate metaclass is determined;
* the c... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
fcf014a5-7b30-5ea7-95d3-26ae2ba7df1b | docs | python | python_datamodel | 313 | 122 | passed to the *bases* parameter, and must return a tuple
of classes that will be used instead of the base. The returned tuple may be
empty: in these cases, the original base is ignored.
See also
[`types.resolve_bases()`](../library/types.html#types.resolve_bases "types.resolve_bases")
: Dynamically reso... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
7b068b04-088c-5d22-96ff-9cfec8ed05b0 | docs | python | python_datamodel | 313 | 123 | * if no bases and no explicit metaclass are given, then [`type()`](../library/functions.html#type "type") is used;
* if an explicit metaclass is given and it is *not* an instance of
[`type()`](../library/functions.html#type "type"), then it is used directly as the metaclass;
* if an instance of [`type()`](../library/... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
f7a2709f-c0b0-55fb-a47e-f2ca5862e889 | docs | python | python_datamodel | 313 | 124 | #### 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 called
as `namespace = metaclass.__prepare__(name, bases, **kwds)` (where... | large_dataset/raw/docs/python/datamodel/datamodel_313.md |
f6c4d741-a5df-5588-99c8-699690a38b88 | docs | python | python_datamodel | 313 | 125 | #### 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_313.md |
a744edd3-a57e-5c02-b5b0-8997598c8f0f | docs | python | python_datamodel | 313 | 126 | `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_313.md |
2c69094b-0f64-5d5d-a2c6-9a2356032abd | docs | python | python_datamodel | 313 | 127 | 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_313.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.