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
6f3b872b-0562-58d9-9b47-1ddcb405d212
docs
python
python_datamodel
310
8
[`__repr__()`](#object.__repr__ "object.__repr__") and [`__str__()`](#object.__str__ "object.__str__"), have the following properties: * They are valid numeric literals which, when passed to their class constructor, produce an object having the value of the original numeric. * The represent...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
45b7edcf-05a7-573a-a142-c6e7b55486ce
docs
python
python_datamodel
310
9
: These represent numbers in an unlimited range, subject to available (virtual) memory only. For the purpose of shift and mask operations, a binary representation is assumed, and negative numbers are represented in a variant of 2’s complement which gives the illusion of an ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
8a82a5d9-b68e-558a-b901-048a19794390
docs
python
python_datamodel
310
10
interpretation of shift and mask operations involving negative integers. [`numbers.Real`](../library/numbers.html#numbers.Real "numbers.Real") ([`float`](../library/functions.html#float "float")) : These represent machine-level double precision floating point numbers. You are at the mercy of ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
479e5db3-6cf4-5186-9809-80fbd56bb238
docs
python
python_datamodel
310
11
floating point numbers. The same caveats apply as for floating point numbers. The real and imaginary parts of a complex number `z` can be retrieved through the read-only attributes `z.real` and `z.imag`. Sequences : These represent finite ordered sets indexed by non-negative numbers. The ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
cfb36370-03d5-56a2-87db-adbc6ddc1fa5
docs
python
python_datamodel
310
12
`>=` `0` and *i* `<=` *x* `<` *j*. Sequences are distinguished according to their mutability: Immutable sequences : An object of an immutable sequence type cannot change once it is created. (If the object contains references to other objects, these other objects may be mutable and ma...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
46630d64-e9ab-5494-8ba6-929b6cff956f
docs
python
python_datamodel
310
13
range `0 - 10FFFF`; [`chr()`](../library/functions.html#chr "chr") converts an integer in the range `0 - 10FFFF` to the corresponding length `1` string object. [`str.encode()`](../library/stdtypes.html#str.encode "str.encode") can be used to convert a [`str`](../library/stdtypes.html...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
6bcb2218-3c16-5263-8608-7afb85f7c779
docs
python
python_datamodel
310
14
tuple can be formed by an empty pair of parentheses. Bytes : A bytes object is an immutable array. The items are 8-bit bytes, represented by integers in the range 0 <= x < 256. Bytes literals (like `b'abc'`) and the built-in [`bytes()`](../library/stdtypes.html#byt...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
fc30e5ec-36a0-58d5-b610-e470046150a1
docs
python
python_datamodel
310
15
that there are no special cases needed to form lists of length 0 or 1.) Byte Arrays : A bytearray object is a mutable array. They are created by the built-in [`bytearray()`](../library/stdtypes.html#bytearray "bytearray") constructor. Aside from being mutable (and ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
058931b8-0aa6-54e7-83fc-2751d2786b6e
docs
python
python_datamodel
310
16
the built-in function [`len()`](../library/functions.html#len "len") returns the number of items in a set. Common uses for sets are fast membership testing, removing duplicates from a sequence, and computing mathematical operations such as intersection, union, difference, and symmetric difference. ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
185f91ac-c4ef-5beb-8328-86aa5a29a95e
docs
python
python_datamodel
310
17
[`frozenset()`](../library/stdtypes.html#frozenset "frozenset") constructor. As a frozenset is immutable and [hashable](../glossary.html#term-hashable), it can be used again as an element of another set, or as a dictionary key. Mappings : These represent finite sets of objects indexed by arbi...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
e22c465d-94d9-5dc2-a53b-20923d0a6562
docs
python
python_datamodel
310
18
object identity, the reason being that the efficient implementation of dictionaries requires a key’s hash value to remain constant. Numeric types used for keys obey the normal rules for numeric comparison: if two numbers compare equal (e.g., `1` and `1.0`) then they can be used interchan...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
a7768b70-8a6d-56cd-99f0-ca62c9be659f
docs
python
python_datamodel
310
19
The extension modules [`dbm.ndbm`](../library/dbm.html#module-dbm.ndbm "dbm.ndbm: The standard \"database\" interface, based on ndbm. (Unix)") and [`dbm.gnu`](../library/dbm.html#module-dbm.gnu "dbm.gnu: GNU's reinterpretation of dbm. (Unix)") provide additional examples of mapping types, as does the [`...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
fdc9e438-bf57-58ef-bc95-792ea98efd00
docs
python
python_datamodel
310
20
section [Function definitions](compound_stmts.html#function)). It should be called with an argument list containing the same number of items as the function’s formal parameter list. Special attributes: | Attribute | Meaning | | | --- | --- | --- | | `__doc__` |...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
6e7f0b44-34a1-52c9-9d4a-d44a81c9d719
docs
python
python_datamodel
310
21
| `__defaults__` | A tuple containing default argument values for those arguments that have defaults, or `None` if no arguments have a default value. | Writable | | `__code__` | The code object representing the compiled function body. | Writable | | `__globals__` | A reference to the dictionary ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
abb183b8-59bc-58b6-bc63-e20d6594112f
docs
python
python_datamodel
310
22
| `__annotations__` | A dict containing annotations of parameters. The keys of the dict are the parameter names, and `'return'` for the return annotation, if provided. For more information on working with this attribute, see [Annotations Best Practices](../howto/annotations.html#annotations-howto). | Writable |...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
370e81e9-5b1f-5801-a82b-01c9d88f2467
docs
python
python_datamodel
310
23
the value of the cell, as well as set the value. Additional information about a function’s definition can be retrieved from its code object; see the description of internal types below. The [`cell`](../library/types.html#types.CellType "types.CellType") type can be accessed in the [`typ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
3021a661-d999-56c1-8de1-c4a0d4e39fce
docs
python
python_datamodel
310
24
Methods also support accessing (but not setting) the arbitrary function attributes on the underlying function object. User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined func...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
4fe234ab-af6f-5178-8d15-7d69e2bdebbd
docs
python
python_datamodel
310
25
(`__func__`) is called, inserting the class instance (`__self__`) in front of the argument list. For instance, when `C` is a class which contains a definition for a function `f()`, and `x` is an instance of `C`, calling `x.f(1)` is equivalent to calling `C.f(x, 1)`. When...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
a025eb76-4de0-5e18-aeb4-2fdfed770476
docs
python
python_datamodel
310
26
objects (and all non-callable objects) are retrieved without transformation. It is also important to note that user-defined functions which are attributes of a class instance are not converted to bound methods; this *only* happens when the function is an attribute of the class. ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
2a6172ae-0d2c-5f20-93e2-9bf8b2fba7c6
docs
python
python_datamodel
310
27
function executes a [`return`](simple_stmts.html#return) statement or falls off the end, a [`StopIteration`](../library/exceptions.html#StopIteration "StopIteration") exception is raised and the iterator will have reached the end of the set of values to be returned. Coroutine functions ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
7de7fb28-3ee4-51d3-ac7e-28bd908dd95d
docs
python
python_datamodel
310
28
which uses the [`yield`](simple_stmts.html#yield) statement is called a *asynchronous generator function*. Such a function, when called, returns an [asynchronous iterator](../glossary.html#term-asynchronous-iterator) object which can be used in an [`async for`](compound_stmts.html#async-...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
3cdc226c-5ac5-5db4-ab11-e3bb76126e15
docs
python
python_datamodel
310
29
the set of values to be yielded. Built-in functions : A built-in function object is a wrapper around a C function. Examples of built-in functions are [`len()`](../library/functions.html#len "len") and [`math.sin()`](../library/math.html#math.sin "math.sin") ([`math`](../library/math.html#modu...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
c9583c18-4c36-5e39-9692-6548a055c691
docs
python
python_datamodel
310
30
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 case, the special read-only attribute `__self__` is set to the object denoted by *alist*. Classes : Classes are cal...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
0ab766b8-2f9f-58f5-a537-199db779fb9c
docs
python
python_datamodel
310
31
the [import system](import.html#importsystem) as invoked either by the [`import`](simple_stmts.html#import) statement, or by calling functions such as [`importlib.import_module()`](../library/importlib.html#importlib.import_module "importlib.import_module") and built-in [`__import__()`](../library/funct...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
992daea6-e099-5e6e-ada5-24f999cfb044
docs
python
python_datamodel
310
32
> : The module’s name. > > `__doc__` > : The module’s documentation string, or `None` if > unavailable. > > [`__file__`](import.html#file__ "__file__") > : The pathname of the file from which the > module was loaded, if it was loaded from a file. > The [`__file_...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
d45ecee8-170c-52f2-995f-bcc31110fb76
docs
python
python_datamodel
310
33
Special read-only attribute: [`__dict__`](../library/stdtypes.html#object.__dict__ "object.__dict__") is the module’s namespace as a dictionary object. **CPython implementation detail:** Because of the way CPython clears module dictionaries, the module dictionary will be cleared when the module falls o...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
29bdb799-b50f-5faf-93a9-19c80f4da96c
docs
python
python_datamodel
310
34
This search of the base classes uses the C3 method resolution order which behaves correctly even in the presence of ‘diamond’ inheritance structures where there are multiple inheritance paths leading back to a common ancestor. Additional details on the C3 MRO used by Python can be found in the docum...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
d1ab3f4b-df53-5f04-85b1-342258df103b
docs
python
python_datamodel
310
35
Class attribute assignments update the class’s dictionary, never the dictionary of a base class. A class object can be called (see above) to yield a class instance (see below). Special attributes: > [`__name__`](../library/stdtypes.html#definition.__name__ "definition.__name__") > : The cla...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
da48f373-4740-552b-aa79-d32e919c2df8
docs
python
python_datamodel
310
36
> collected during class body execution. For best practices on > working with `__annotations__`, please see > [Annotations Best Practices](../howto/annotations.html#annotations-howto). Class instances : A class instance is created by calling a class object (see above). A class instance ha...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
21fb02cb-3c14-5d7d-aca6-48396fd436d2
docs
python
python_datamodel
310
37
retrieved via its instances may differ from the objects actually stored in the class’s [`__dict__`](../library/stdtypes.html#object.__dict__ "object.__dict__"). If no class attribute is found, and the object’s class has a [`__getattr__()`](#object.__getattr__ "object.__getattr__") method, that is called to ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
a48c52a9-d296-5625-9692-23f1e43b6571
docs
python
python_datamodel
310
38
[`__class__`](../library/stdtypes.html#instance.__class__ "instance.__class__") is the instance’s class. I/O objects (also known as file objects) : A [file object](../glossary.html#term-file-object) represents an open file. Various shortcuts are available to create file objects: the [`open()`](../library/fun...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
40a6be3c-1e36-5966-b303-ee1277eb000d
docs
python
python_datamodel
310
39
abstract class. Internal types : A few types used internally by the interpreter are exposed to the user. Their definitions may change with future versions of the interpreter, but they are mentioned here for completeness. Code objects : Code objects represent *byte-compiled* executable Python c...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
7432a80a-2a51-5389-8b17-b1b334131d59
docs
python
python_datamodel
310
40
`co_argcount` is the total number of positional arguments (including positional-only arguments and arguments with default values); `co_posonlyargcount` is the number of positional-only arguments (including arguments with default values); `co_kwonlyargcount` is the number of keywo...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
5926510b-08b5-5939-86c4-69508bdea39e
docs
python
python_datamodel
310
41
a tuple containing the names used by the bytecode; `co_filename` is the filename from which the code was compiled; `co_firstlineno` is the first line number of the function; `co_lnotab` is a string encoding the mapping from bytecode offsets to line numbers (for details see the so...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
bc69f2d2-49a8-5699-bd7e-f372087d04ce
docs
python
python_datamodel
310
42
particular feature enabled: bit `0x2000` is set if the function was compiled with future division enabled; bits `0x10` and `0x1000` were used in earlier versions of Python. Other bits in `co_flags` are reserved for internal use. If a code object represents a function, the first...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
d35fb03b-55cf-52d4-ad0b-58a3704b790a
docs
python
python_datamodel
310
43
`f_lasti` gives the precise instruction (this is an index into the bytecode string of the code object). Accessing `f_code` raises an [auditing event](../library/sys.html#auditing) `object.__getattr__` with arguments `obj` and `"f_code"`. Special writable attributes: `f_trace`, ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
eac2c926-ffce-5d9f-b7cb-a32eb8a7a585
docs
python
python_datamodel
310
44
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 f\_lineno. Frame objects support one method: `frame.``clear`()[¶](#frame.clear "Permalink to this definition") ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
c50ac635-db50-57ef-a795-3462c1728afa
docs
python
python_datamodel
310
45
created by calling [`types.TracebackType`](../library/types.html#types.TracebackType "types.TracebackType"). For implicitly created tracebacks, when the search for an exception handler unwinds the execution stack, at each unwound level a traceback object is inserted in front of the curr...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
9066cef4-8943-5115-b91c-80513e2c8a4e
docs
python
python_datamodel
310
46
to determine how the `tb_next` attributes should be linked to form a full stack trace. Special read-only attributes: `tb_frame` points to the execution frame of the current level; `tb_lineno` gives the line number where the exception occurred; `tb_lasti` indicates the pr...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
2979df9c-7445-54b0-8b02-d2f51610383b
docs
python
python_datamodel
310
47
Changed in version 3.7: Traceback objects can now be explicitly instantiated from Python code, and the `tb_next` attribute of existing instances can be updated. Slice objects : Slice objects are used to represent slices for [`__getitem__()`](#object.__getitem__ "object.__getitem__") ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
ffeac1c9-286e-5188-8bb2-8503aece0e9e
docs
python
python_datamodel
310
48
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 manner consistent with regular slices. Static method objects : Static method objects provide a way of defeating t...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
87f87022-f6d5-5a6f-95a2-9e51a887d4ae
docs
python
python_datamodel
310
49
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 is described above, under “User-defined methods”. Class method objects are created by the built-in [`classmethod()`](../library/functio...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
2017c1b1-279e-5725-8fb3-7c25e40cc146
docs
python
python_datamodel
310
50
operation raise an exception when no appropriate method is defined (typically [`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 availabl...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
a2af9da3-8200-5504-b77f-9272101e85f9
docs
python
python_datamodel
310
51
of this is the `NodeList` interface in the W3C’s Document Object Model.) ### 3.3.1. Basic customization[¶](#basic-customization "Permalink to this headline") `object.``__new__`(*cls*[, *...*])[¶](#object.__new__ "Permalink to this definition") : Called to create a new instance of class *cls*. [`__new__()`](#object....
large_dataset/raw/docs/python/datamodel/datamodel_310.md
ae949949-0a8f-58a2-9ab4-cb649951f0b4
docs
python
python_datamodel
310
52
as necessary before returning it. 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...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
ce7c3412-9e56-5ef0-9548-db4a83964222
docs
python
python_datamodel
310
53
: 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_310.md
789acc2a-d983-5e6b-b0dc-c93dd5767077
docs
python
python_datamodel
310
54
cause a [`TypeError`](../library/exceptions.html#TypeError "TypeError") to be raised at runtime. `object.``__del__`(*self*)[¶](#object.__del__ "Permalink 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...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
12e0b324-f6b7-58e7-93c7-46c68cf36d0f
docs
python
python_datamodel
310
55
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. Note `del x` doesn’t directly...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
bb92f925-c5fa-5cc0-9e78-e134f1e1f792
docs
python
python_datamodel
310
56
See also Documentation for the [`gc`](../library/gc.html#module-gc "gc: Interface to the cycle-detecting garbage collector.") module. Warning Due to the precarious circumstances under which [`__del__()`](#object.__del__ "object.__del__") methods are invoked, exceptions that occur during their ex...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
cad41982-351d-5320-b9b2-2af9929d201b
docs
python
python_datamodel
310
57
modules) may already have been deleted or set to `None`. Python guarantees that globals whose name begins with a single underscore are deleted from their module before other globals are deleted; if no other references to such globals exist, this may help in assuring that imported modules a...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
534af395-d8f7-58f0-8f62-8e1a46164f2a
docs
python
python_datamodel
310
58
The return value must be a string object. If a class defines [`__repr__()`](#object.__repr__ "object.__repr__") but not [`__str__()`](#object.__str__ "object.__str__"), then [`__repr__()`](#object.__repr__ "object.__repr__") is also used when an “informal” string representation of instances of that class is...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
64bc83d0-4b4d-57c1-ab6c-ab0e598dec17
docs
python
python_datamodel
310
59
expectation that [`__str__()`](#object.__str__ "object.__str__") return a valid Python expression: a more 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._...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
4eeb7f58-8a85-572c-b457-d5660eb42dc4
docs
python
python_datamodel
310
60
and by extension, evaluation of [formatted string literals](lexical_analysis.html#f-strings) and the [`str.format()`](../library/stdtypes.html#str.format "str.format") method, to produce a “formatted” string representation of an object. The *format\_spec* argument is a string that contains a description of ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
97a211f1-eac2-5a89-ba8f-35aed6f07ac4
docs
python
python_datamodel
310
61
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__ "Permalink to this definition") `object.``__le__`(*self*, *other*)[¶](#object.__le__ "Permalink to this definition") `object.``__eq__`(*self*...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
7be986f8-13bb-508d-92a5-74cae6766f7f
docs
python
python_datamodel
310
62
A rich comparison method may return the singleton `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 return any value, so if the comparison operator is used in a Boo...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
9824e1f5-68d2-5221-8fae-caebf0fad640
docs
python
python_datamodel
310
63
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/functools.html#functools.total_ordering "functools.total_ordering"). ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
28324040-da45-58a0-8ff3-9e4d7c043589
docs
python
python_datamodel
310
64
[`__eq__()`](#object.__eq__ "object.__eq__") and [`__ne__()`](#object.__ne__ "object.__ne__") are their own reflection. If the operands are of different types, and right operand’s type is a direct or indirect subclass of the left operand’s type, the reflected method of the right operand has priority, ot...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
efa343bf-215b-54c2-946f-54ebf5bc5f7c
docs
python
python_datamodel
310
65
advised to mix together the hash values of the components of the object that also play a part in comparison of objects by packing them into a tuple and hashing the tuple. Example: ```None def __hash__(self): return hash((self.name, self.nick, self.color)) ``` Note [`hash()`](....
large_dataset/raw/docs/python/datamodel/datamodel_310.md
9de29bce-860d-5f0d-a21f-e7e187820423
docs
python
python_datamodel
310
66
[`__hash__()`](#object.__hash__ "object.__hash__") operation either; if it defines [`__eq__()`](#object.__eq__ "object.__eq__") but not [`__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 ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
109b53ba-ae74-5cb0-97a6-514964767e0d
docs
python
python_datamodel
310
67
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_310.md
ea7cbb99-6402-5742-8c20-c3db81b13114
docs
python
python_datamodel
310
68
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_310.md
f1448ab2-1d9a-5965-a8b9-f8f8a3007836
docs
python
python_datamodel
310
69
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_310.md
1d04c98c-6368-53ae-b240-63f67d2a4945
docs
python
python_datamodel
310
70
### 3.3.2. Customizing attribute access[¶](#customizing-attribute-access "Permalink to this headline") 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__ "...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
3bd4d679-3f23-5639-9cac-c0e92dde85fe
docs
python
python_datamodel
310
71
attribute value or raise an [`AttributeError`](../library/exceptions.html#AttributeError "AttributeError") exception. Note that if the attribute is found through the normal mechanism, [`__getattr__()`](#object.__getattr__ "object.__getattr__") is not called. (This is an intentional asymmetry between [`...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
164943b0-f3f9-5990-844c-312819835e4a
docs
python
python_datamodel
310
72
`object.``__getattribute__`(*self*, *name*)[¶](#object.__getattribute__ "Permalink to this definition") : Called unconditionally to implement attribute accesses for instances of the class. If the class also defines [`__getattr__()`](#object.__getattr__ "object.__getattr__"), the latter will not be called unle...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
88941ef5-6876-515e-bf83-23108b3d7b16
docs
python
python_datamodel
310
73
result of implicit invocation via language syntax or built-in functions. See [Special method lookup](#special-lookup). For certain sensitive attribute accesses, raises an [auditing event](../library/sys.html#auditing) `object.__getattr__` with arguments `obj` and `name`. `object.``__setattr__`(*se...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
d8aabc45-6e1b-5faa-a878-742ec5bcf2db
docs
python
python_datamodel
310
74
`obj`, `name`, `value`. `object.``__delattr__`(*self*, *name*)[¶](#object.__delattr__ "Permalink to this definition") : 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 ob...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
b70437fd-29bc-507e-95c6-01a5d59dad3c
docs
python
python_datamodel
310
75
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_310.md
06f1da66-8e7d-53d2-8ae8-982d58bd1e35
docs
python
python_datamodel
310
76
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 class VerboseModule(ModuleType): def __repr__(self): return...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
c97ae01b-ba05-5383-acb0-e48e58d51505
docs
python
python_datamodel
310
77
[**PEP 562**](https://www.python.org/dev/peps/pep-0562) - Module \_\_getattr\_\_ and \_\_dir\_\_ : Describes the `__getattr__` and `__dir__` functions on modules. #### 3.3.2.2. Implementing Descriptors[¶](#implementing-descriptors "Permalink to this headline") The following methods only apply when an instance of th...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
bcd32857-85b2-5da7-880b-505302b9dbf1
docs
python
python_datamodel
310
78
*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 or raise an [`AttributeError`](../library/exceptions.html#AttributeErro...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
dc404bbc-e002-5d7a-898c-e431e9c820f7
docs
python
python_datamodel
310
79
: 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_310.md
897177e5-64f8-5141-99bd-5ad8a140315e
docs
python
python_datamodel
310
80
CPython sets this attribute for unbound methods that are implemented in C). #### 3.3.2.3. Invoking Descriptors[¶](#invoking-descriptors "Permalink to this headline") In general, a descriptor is an object attribute with “binding behavior”, one whose attribute access has been overridden by methods in the descriptor pro...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
e469675f-2ef2-58d8-879b-6744b667f4a2
docs
python
python_datamodel
310
81
method instead. Where this occurs in the precedence chain depends on which 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 di...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
98be40d2-ea00-5ebd-a46e-813a6d4f802c
docs
python
python_datamodel
310
82
For instance bindings, the precedence of descriptor invocation depends on which descriptor methods are defined. A descriptor can define any combination of [`__get__()`](#object.__get__ "object.__get__"), [`__set__()`](#object.__set__ "object.__set__") and [`__delete__()`](#object.__delete__ "object.__delete__"). If it ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
155cf043-7bcd-5fe3-900f-1a1e6c545bbd
docs
python
python_datamodel
310
83
[`@staticmethod`](../library/functions.html#staticmethod "staticmethod") and [`@classmethod`](../library/functions.html#classmethod "classmethod")) are implemented as non-data descriptors. Accordingly, instances can redefine and override methods. This allows individual instances to acquire behaviors that differ from ot...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
5605df53-d5bf-5f35-b12d-90193d19411e
docs
python
python_datamodel
310
84
Attribute lookup speed can be significantly improved as well. `object.``__slots__`[¶](#object.__slots__ "Permalink to this definition") : This class variable can be assigned a string, iterable, or sequence of strings with variable names used by instances. *\_\_slots\_\_* reserves space for the declared varia...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
546ac937-5647-54fd-b440-298d9f33723e
docs
python
python_datamodel
310
85
listed in the *\_\_slots\_\_* definition. Attempts to assign to an unlisted 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....
large_dataset/raw/docs/python/datamodel/datamodel_310.md
c88dd350-cfdd-59ce-bfd1-406f2c563297
docs
python
python_datamodel
310
86
* The action of a *\_\_slots\_\_* declaration is not limited to the class where it is defined. *\_\_slots\_\_* declared in parents are available in child classes. However, child subclasses will get a [`__dict__`](../library/stdtypes.html#object.__dict__ "object.__dict__") and *\_\_weakref\_\_* unless they also de...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
a284bae1-c550-50b8-be88-ab8497a37ec0
docs
python
python_datamodel
310
87
[`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_310.md
6e169fc7-8d58-5156-a784-0f80def454d0
docs
python
python_datamodel
310
88
(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_310.md
df7fa471-d15a-5f64-be4b-3071bf101326
docs
python
python_datamodel
310
89
*classmethod* `object.``__init_subclass__`(*cls*)[¶](#object.__init_subclass__ "Permalink 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. ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
c4c7e940-68ed-50c6-a5d8-7f1f1732a04c
docs
python
python_datamodel
310
90
Note 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)`. New in version 3.6. When a class is created, `type.__new__()` sca...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
627171e1-5bac-5493-a240-4f83e875041f
docs
python
python_datamodel
310
91
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_310.md
a8739794-0347-5b0d-8935-ccfbf6e19167
docs
python
python_datamodel
310
92
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 ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
8c958b82-b446-57d2-af63-141b4e0fd4c4
docs
python
python_datamodel
310
93
#### 3.3.3.3. Determining the appropriate metaclass[¶](#determining-the-appropriate-metaclass "Permalink to this headline") The appropriate metaclass for a class definition is determined as follows: * if no bases and no explicit metaclass are given, then [`type()`](../library/functions.html#type "type") is used; * if...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
7a013f8a-414f-5c21-b989-855ca00cad98
docs
python
python_datamodel
310
94
#### 3.3.3.4. Preparing the class namespace[¶](#preparing-the-class-namespace "Permalink to this headline") 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)` ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
9fd4c04d-4ab3-519a-b9a4-46c714816748
docs
python
python_datamodel
310
95
#### 3.3.3.5. Executing the class body[¶](#executing-the-class-body "Permalink to this headline") 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 (i...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
6a3590a8-0153-51b5-b8e8-8b191b3f19b2
docs
python
python_datamodel
310
96
`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_310.md
462b320c-f29e-58b8-a390-cda58c0940d7
docs
python
python_datamodel
310
97
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_310.md
55b143e8-59ce-5838-a4b1-889de6e655d4
docs
python
python_datamodel
310
98
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__`](../library/stdtypes.html#object.__dict__ "object.__dict__") attribute of the...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
20ba6a37-a08e-5b98-86d1-bc81b045f3f4
docs
python
python_datamodel
310
99
### 3.3.4. Customizing instance and subclass checks[¶](#customizing-instance-and-subclass-checks "Permalink to this headline") The following methods are used to override the default behavior of the [`isinstance()`](../library/functions.html#isinstance "isinstance") and [`issubclass()`](../library/functions.html#issubc...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
9b32069c-9522-579d-94cf-6c43809c54b7
docs
python
python_datamodel
310
100
: Return true if *subclass* should be considered a (direct or indirect) subclass of *class*. If defined, called to implement `issubclass(subclass, class)`. 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...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
834363a3-7541-5a4c-859d-3ae1b76eecd7
docs
python
python_datamodel
310
101
in the context of adding Abstract Base Classes (see the [`abc`](../library/abc.html#module-abc "abc: Abstract base classes according to :pep:`3119`.") module) to the language. ### 3.3.5. Emulating generic types[¶](#emulating-generic-types "Permalink to this headline") When using [type annotations](../glossary...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
4676553c-4150-55fe-9f48-c7b78a08c338
docs
python
python_datamodel
310
102
[Generics](../library/typing.html#generics), [user-defined generics](../library/typing.html#user-defined-generics) and [`typing.Generic`](../library/typing.html#typing.Generic "typing.Generic") : Documentation on how to implement generic classes that can be parameterized at runtime and understood by static type-c...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
cf50d685-87b1-5972-a157-3d9cc69b2755
docs
python
python_datamodel
310
103
#### 3.3.5.1. The purpose of *\_\_class\_getitem\_\_*[¶](#the-purpose-of-class-getitem "Permalink to this headline") The purpose of [`__class_getitem__()`](#object.__class_getitem__ "object.__class_getitem__") is to allow runtime parameterization of standard-library generic classes in order to more easily apply [type ...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
50ef30df-e98c-54f6-b0ba-4d8a3de5d64b
docs
python
python_datamodel
310
104
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 "Permalink to this headline") Usually, the [subscription](expressions.html#subscriptions) of an obj...
large_dataset/raw/docs/python/datamodel/datamodel_310.md
28fa04bb-f2c0-5e98-9d12-526fdd8acf84
docs
python
python_datamodel
310
105
[`__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_310.md
c80393df-83a8-57da-8951-1b6389636918
docs
python
python_datamodel
310
106
[`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_310.md
8da3815e-577d-5241-9a8c-ccae2841021e
docs
python
python_datamodel
310
107
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_310.md