Title: Theory / Important / CS / Programming / Python / Manual{ / 3 Data model
Tags: hasNotNewEffectReturnsMeaning fromMath FromInstruction computer_to_instruction mathToDef some_instruction defToType mathToSee récupéré seen_description automatedNewLineAfterCommaSpace constant hasSeenConjDef type defToComputer syntactical_sugar
On every note of this deck, unless a note says otherwise:
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors

Name: object
Definition: identity
Chapter: 3
Section: 1
Definition2: type
Conjdef: An element with
Definition3: value

Name: The identity of o
Definition: which never changes once the object o is created.
Chapter: 3
Section: 1
Variables: o an object
Definition2: distinct than the same thing, for each other objects
Conjdef: A value

Name: The type of an object
Definition: The operations that the object supports.
Chapter: 3
Section: 1
Variables: \(o\) an object

Name: A mutable object
Definition: An object whose value can change.
Chapter: 3
Section: 1
Context: python
Example: list
Example2: set and dictionaries

Name: An immutable object
Definition: An object whose value can't be changed once they are created.
Chapter: 3
Section: 1
Context: Python
Example: number
Example2: tuple
Example3: string
Example4: frozen set

Name: Containers
Definition: An object which contain references to other objects.
Chapter: 3
Section: 1
Example: tuples
Example2: list
Example3: dictionnaries

Constant: Ellipsis
Abbreviation: ...

Question: Null's truth value is
Answer: false
Chapter: 3
Section: 2

Question: NotImplemented's truth value is
Answer: true
Chapter: 3
Section: 2

Question: Ellipsis's truth value is
Answer: true
Chapter: 3
Section: 2

Typ: int
Meaning: Any relative integers, in base 2, with virtually an infinite number of bits
Language: Python
Chapter: 3
Section: 2
Subtype of: Numbers.Integral

Typ: bool
Meaning: False and True. There behaviors is similar to 0 and 1, except when transformed in string where it is "False" and "True"
Language: Python
Chapter: 3
Section: 2
Subtype of: Numbers.Integral

Typ: numbers.Integral
Meaning: int and bool
Language: Python
Chapter: 3
Section: 2
Subtype of: Numbers.numbers

Meaning: The machine and compiler dependant double precision floating point numbers
Language: Python
Chapter: 3
Section: 2
Subtype of: Numbers.numbers
Name: float

Typ: complex
Meaning: Complex numbers using float.
Language: Python
Chapter: 3
Section: 2

Typ: Sequence
Meaning: Finite ordered sets indexed by non-negative numbers.
Language: Python
Chapter: 3
Section: 2

Typ: Immutable sequence
Meaning: A sequence which can not be changed.
Language: Python
Chapter: 3
Section: 2
Subtype of: Sequences
Extra: If its elements are mutable, its elements can be changed
Example: string, tuple, byte

Typ: String
Meaning: A sequence of values that represent Unicode code points.
Language: Python
Chapter: 3
Section: 2
Subtype of: Immutable sequences

Typ: Bytes
Meaning: Immutable array of 8-bit bytes.
Language: Python
Chapter: 3
Section: 2
Subtype of: Immutable sequences

Typ: Lists
Meaning: A mutable sequence of objects.
Language: Python
Chapter: 3
Section: 2
Subtype of: Mutable sequences

Name: Tuples
Definition: Immutable sequences of arbitrary object
Chapter: 3
Section: 2
Context: Python

Name: Byte Arrays
Definition: A mutable array of byte
Chapter: 3
Section: 2
Typ: Mutable sequences

Instruction: bytearray()
Language: Python
Chapter: 3
Section: 2
Returns: A bytearray of size 0

Name: Set types
Definition: unordered, finite sets of unique, immutable objects.
Chapter: 3
Section: 2

Name: Sets
Definition: A mutable set.
Chapter: 3
Section: 2
Typ: Set types

Name: Frozen Sets
Definition: An immutable set.
Chapter: 3
Section: 2
Typ: Set types

Name: Mappings
Definition: Finite sets of objects indexed by arbitrary index sets.
Chapter: 3
Section: 2

Name: Dictionaries
Definition: Sets of objects indexed by values which does not contains mutable type which are compared by values and not by identity.
Chapter: 3
Section: 2
Typ: Mappings

Name: Callable type
Definition: Types to which the function call operation can be applied.
Chapter: 3
Section: 1

Name: User-defined functions
Definition: Object created by a function definition.
Chapter: 3
Section: 1
Variables: Writable

Name: Instance methods
Definition: An object which combines a class, a class instance and any callable object
Chapter: 3
Section: 2
Context: Python
Assuming: \(f\) is user defined

Instruction: f.__func__
Effect: The function object of f
Language: Python
Chapter: 3
Section: 2

Instruction: instance method rules
Language: Python
Chapter: 3
Section: 2
Typ: To be done after class

Name: Generator functions
Definition: A function or method which uses the yield statement
Chapter: 3
Section: 2
Typ: Returns an iterator object

Name: Asynchronous generator functions
Definition: A function or method which is defined using async def and which uses the yield statement.
Chapter: 3
Section: 2

Name: Built-in function
Definition: A wrapper around a C function.
Chapter: 3
Section: 2
Context: Python

Name: Built-in method
Definition: A wrapper around a C function, with an implicit extra argument.
Chapter: 3
Section: 2

Name: Classes
Definition: Factories for new instances of themselves.
Chapter: 3
Section: 2
Typ: Callable

Name: Class instance
Definition: An object generating with `C()` for `C` a class
Page: https://docs.python.org/3/reference/datamodel.html#customizing-attribute-access
Chapter: 3
Section: 2
Intuition: Object in m

Instruction: o.__dir__(self)
Effect: A sequence of ???
Language: Python
Chapter: 3
Section: 3.2
Variables: o an object
Abbreviation: dir(o)

Instruction: o.__get_(self,instance,owner)
Language: Python
Chapter: 3
Section: 3.2.1
Returns: the (computed) attribute of the owner class (class attribute access) or of an instance of that class (instance attribute access)
Variables: o an object
Assuming: owner is always the owner class, while instance is the instance that the attribute was accessed through, or None when the attribute is accessed through the owner
Exception: raise an AttributeError exception if it can't get value

Instruction: o.__set_(self,instance,owner)
Effect: Called to set the attribute on an instance instance of the owner class to a new value,
Language: Python
Chapter: 3
Section: 3.2.1
Variables: o an object

Instruction: stop
Effect: move to 4
Language: Python
Chapter: 3
Section: 3.2.1
Variables: o an object

Instruction: isinstance(object, class)
Page: https://docs.python.org/3/tutorial/classes.html
Language: Python
Chapter: 9, 3
Section: 4, 3.4
Returns: Whether the class of object is class
class.__instancecheck__(object)
Variables: c a class,
o a variable

Instruction: a is b
Language: Python
Chapter: 3
Section: 1
Returns: whether a is the same object as b

Instruction: id(a)
Page: https://docs.python.org/3/reference/datamodel.html
Language: Python
Chapter: 3
Section: 1
Returns: An integer representing the identity of a
Intuition: memory address in CPython

Constant: None

Constant: NotImplemented

Instruction: f.__annotations__
Language: Python
Chapter: 3
Section: 1
Returns: A dict containing annotations of parameters. The keys of the dict are the parameter names, and 'return' for the return annotation, if provided.
Variables: f a function
Typ: Writable

Instruction: object.__new__(
  cls[,
  ...]
)
Effect: Called to create a new instance of class cls
Language: Python
Chapter: 3
Section: 3.1

Instruction: object.__del__(self)
Effect: Called when the instance is about to be destroyed.
Language: Python
Chapter: 3
Section: 3.1
Extra: not destructor, contrary to other language, as it does not destroy anything.
Name: finalizer
Intuition: Allow to close resource, log the event...
Exception: thrown expressions are ignored and printed on sys.stderr

Instruction: foo.__bytes__()
Language: Python
Chapter: 3
Section: 3.1
Returns: a byte-string representation of an object
Abbreviation: bytes(foo)
Typ: bytes

Instruction: const
Page: 209
Language: Haskell
Chapter: 8
Returns: (lambda x y: x)
Typ: a->b->a
Name: K
Intuition: const x represents the function constant b -> a

Instruction: o.__getattr__(
  self,
  name
)
Language: Python
Chapter: 3
Section: 3.2
Returns: A value representing self.name or
Variables: o an object

Instruction: o.__getattribute__(self,name)
Language: Python
Chapter: 3
Section: 3.2
Returns: The expected value for self.name
Variables: o an object
Exception: AttributeError if the attribute can't be found/computed

Instruction: o.__setattr__(self,name,value)
Effect: Called when an attribute assignment is attempted. This is called instead of the normal mechanism (i.e. store the value in the instance dictionary). name is the attribute name, value is the value to be assigned to it.
If it wants to assign to an instance attribute, it should call the base class method with the same name, for example, object.__setattr__(self, name, value)
Language: Python
Chapter: 3
Section: 3.2
Variables: o an object

Instruction: o.__delattr__(self,name)
Effect: Like __setattr__() but for attribute deletion instead of assignment. This should only be implemented if del obj.name is meaningful for the object.
Language: Python
Chapter: 3
Section: 3.2
Variables: o an object

Instruction: o.__delete__(self,instance)
Effect: Called to delete the attribute on an instance instance of the owner class.
Language: Python
Chapter: 3
Section: 3.2.1
Variables: o an object

Instruction: o.__set_name__(self,owner,name)
Effect: Called at the time the owning class owner is created. The descriptor has been assigned to name.
Language: Python
Chapter: 3
Section: 3.2.1
Variables: o an object

Instruction: o.__objclass
Effect: specifying the class where this object was defined (setting this 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 C).
Language: Python
Chapter: 3
Section: 3.2.1
Variables: o an object

Instruction: s.__contains__(x)
Page: https://docs.python.org/3/library/stdtypes.html#frozenset
Language: Python
Chapter: 3
Section: 3.7
Returns: Whether s contains an object equal to x
Variables: s a container
Abbreviation: x in s

Instruction: foo.__repr__()
Page: https://docs.python.org/3/reference/datamodel.html#customizing-attribute-access
Language: Python
Chapter: 3
Section: 3.1
Returns: if possible an expression allowing to recreate the value
otherwise <...some useful description...>
Variables: foo an object
Abbreviation: repr(foo)
Typ: String

Instruction: foo.__str__() (by default defined as `return foo.__repr__()`
Page: 11
Language: Python
Chapter: 1
Returns: nicely printable string representation of an obje
Abbreviation: str(foo)
Typ: string

Instruction: o.__objclass__
Page: https://docs.python.org/3/reference/datamodel.html#customizing-class-creation
Language: Python
Chapter: 3
Section: 3.2.1
Returns: specifying the class where this object was defined

Instruction: __slots__
Page: https://docs.python.org/3/reference/datamodel.html#object.__getattr__
Language: Python
Context: class definition
Returns: An iterable containing the entire list of possible attributes for this class

Question: What occurs when calling super(cl,obj).x
Answer: Find the class A before cl in the mro of obj
Page: https://docs.python.org/3/reference/datamodel.html#object.__getattr__
Variables: cl an object,
obj an object
Answer2: A.__dict__['x'].__get__(obj, obj.__class__)

Name: A data descriptor
Definition: A descriptor implementing __get__ and __set__
Page: https://docs.python.org/3/reference/datamodel.html#object.__getattr__

Name: A non-data descriptor
Definition: A descriptor implementing __get__ and not __set__
Page: https://docs.python.org/3/reference/datamodel.html#object.__getattr__

Instruction: type(a)
Page: https://docs.python.org/3/reference/datamodel.html
Context: Python
Chapter: 3
Section: 1
Returns: the type of a
Variables: a an object

Question: Guarantee of python garbage collector
Answer: never deleting anything reachable (in particular, no GC is valid)
Page: https://docs.python.org/3/reference/datamodel.html
Section: 1
Context: Python

Question: How is implemented garbage collector in CPython currently (3.10)
Answer: reference-counting scheme
Page: https://docs.python.org/3/reference/datamodel.html
Section: 1
Context: Python
Answer2: (optional) delayed detection of cyclically linked garbage

Question: What may keep an object alive and not garbage collected while not being actually reachable by code
Answer: implementation's tracing/debugging facility
Page: https://docs.python.org/3/reference/datamodel.html
Section: 1
Context: Python
Answer2: catching an exception with a try... except statement, ensuring that the stackframe is in a variable and can not be freed

Question: Difference between
a = b = []
and
a = []; b = []
Answer: in the first case, both variables refer to the same object, in the second to two distinct objects
Page: https://docs.python.org/3/reference/datamodel.html
Chapter: 3
Section: 1
Context: Python

Instruction: m.__file__
Page: https://docs.python.org/3/reference/datamodel.html
Context: Python
Chapter: 3
Section: 2
Returns: The pathname of the file from which the module was loaded, if it was loaded from a file.
Variables: m a module

Instruction: m.__annotations__
Page: https://docs.python.org/3/reference/datamodel.html
Context: Python
Section: 2
Returns: A dictionary containing variable annotations collected during module body execution.
Variables: m a module/class

Instruction: m.__dict__
Page: https://docs.python.org/3/reference/datamodel.html
Context: Python
Section: 2
Returns: the module’s namespace as a dictionary object.
Variables: m a module

Instruction: c.__bases__
Page: https://docs.python.org/3/reference/datamodel.html
Language: Python
Section: 2
Returns: A tuple containing the base classes, in the order of their occurrence in the base class list.
Variables: C a class

Name: A frame object
Definition: represent execution frame
Page: https://docs.python.org/3/reference/datamodel.html
Section: 2

Name: A code object
Definition: An object representing byte-compiled executable python code
Page: https://docs.python.org/3/reference/datamodel.html
Section: 2

Name: A traceback object
Definition: represent a stack trace of an exception
Page: https://docs.python.org/3/reference/datamodel.html
Section: 2

Name: Internal type
Definition: A type used internally, by the interpreter, but are exposed to user in some case. The details may change with python evolution
Page: https://docs.python.org/3/reference/datamodel.html
Section: 2
Example: code object
Example2: frame and traceback objects

Question: What is the point of __new__
Answer: mainly to allow subclasses of immutable types (like int, str, or tuple) to customize instance creation
Page: https://docs.python.org/3/reference/datamodel.html
Chapter: 3
Section: 3.1
Answer2: commonly overridden in custom metaclasses in order to customize class creation.

Question: difference between del x and x.__del__
Answer: del x is applied to the variable x. If the object is still referenced somewhere else, the object won't be finalized and so __del__ is not called
Page: https://docs.python.org/3/reference/datamodel.html
Chapter: 3
Section: 3.1

Instruction: x < y
Page: https://docs.python.org/3/reference/datamodel.html
Chapter: 3
Section: 3.1
Returns: x.__lt__(y)
unless type(y) is a subtype of type(x), then y.__gt__(x)
Variables: x, y objects

Instruction: x <= y
Page: https://docs.python.org/3/reference/datamodel.html
Chapter: 3
Section: 3.1
Returns: x.__le__(y)
unless type(y) is a subtype of type(x), then y.__ge__(x)
Variables: x, y objects

Instruction: x >= y
Page: https://docs.python.org/3/reference/datamodel.html
Section: 3.1
Returns: x.__ge__(y)
unless type(y) is a subtype of type(x), then y.__le__(x)
Variables: x, y objects

Instruction: x > y
Page: https://docs.python.org/3/reference/datamodel.html
Section: 3.1
Returns: x.__gt__(y)
unless type(y) is a subtype of type(x), then y.__lt__(x)
Variables: x, y objects

Instruction: x == y
Page: https://docs.python.org/3/reference/datamodel.html
Section: 3.1
Returns: x.__eq__(y)
unless type(y) is a subtype of type(x), then y.__eq__(x)
Variables: x, y objects

Instruction: x != y
Page: https://docs.python.org/3/reference/datamodel.html
Section: 3.1
Returns: x.__ne__(y)
unless type(y) is a subtype of type(x), then y.__ne__(x)
Variables: x, y objects

Question: default implementation of __ne__(self, other)
Answer: return not self.__eq__(other)
Page: https://docs.python.org/3/reference/datamodel.html
Chapter: 3
Section: 3.1
Context: python

Question: default implementation of __str__(self, other)
Answer: return not self.__repr__(other)
Page: https://docs.python.org/3/reference/datamodel.html
Chapter: 3
Section: 3.1
Context: python

Question: default implementation of __bool__(self)
Answer: return self.__len__() != 0
Page: https://docs.python.org/3/reference/datamodel.html
Chapter: 3
Section: 3.1
Context: python

Syntactic sugar: a.x
Implementation: type(a).__dict__['x'].__get__(a, type(a)).
Language: Python
Section: 3.2.3
Variables: C a class
x a descriptor (has __get__ implemented)
a an object instance of C
Chapter: 3
Name: Instance Binding

Syntactic sugar: C.x
Implementation: C.__dict__['x'].__get__(None, C)
Language: Python
Section: 3.2.3
Variables: C a class
x a descriptor (has __get__ implemented)
Chapter: 3
Name: Class Binding

Syntactic sugar: super(B, obj).m()
Implementation: A = base class immediately preceding B in obj.__class__.__mro__
A.__dict__['m'].__get__(obj, obj.__class__)
Language: Python
Section: 3.2.3
Variables: B a class,
obj an object
Chapter: 3
Name: Super Binding

Instruction: __slots__ = ["var_1", ..., "var_n"]
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Meaning: the only variables the class C can have are var_1, ..., var_n
Language: Python
Chapter: 3
Section: 3.2.4
Where to use it: Class declaration C

Question: Restriction on class assignment
Answer: A class can be assigned to another one only if they have the same __slots__ (potentially no __slots__)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.2.4

Question: Restriction on inheritance with __slots__
Answer: A class should not use a slot used by an ancestor
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.2.4
Answer2: At most one parent can have attribute created by slot value

Name: A slot
Definition: C.x for some x in C.__slots__
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.2.4
Variables: C a class
Context: Python

Variable: __init__subclass(cls, /, **kwargs)
Meaning: `class D (C, keyword_args...):` call it with arguments `(D, keyword_args)`
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: Python
Section: 3.3
Chapter: 3
Variables: C a class
Initialization: if kwargs:
  raise

Variable: __set_name_(self, owner, name)
Meaning: In a class declaration, `var = expr` call `var.__set_name_(A, 'var')`
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: Python
Section: 3.3
Chapter: 3
Variables: A class declaration A

Question: Differenc between, in class A declaration
  var = expr
and outside of the declaration
A.var = expr
Answer: The first one call var.__set_name_(A, 'var')
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.3

Question: Order of action in class definition
Answer: MRO entries are resolved;
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.3.1
Answer2: the appropriate metaclass is determined;
Answer3: the class namespace is prepared;
Answer4: the class body is executed;
Answer5: the class object is created.

Question: How is determined MRO entries?
Answer: todo
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.3.1

Question: How is determined the metaclass
Answer: if no bases and no explicit metaclass are given, then type() is used;
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.3.1
Answer2: if an explicit metaclass is given and it is not an instance of type(), then it is used directly as the metaclass;
Answer3: if an instance of type() is given as the explicit metaclass, or bases are defined, then the most derived metaclass is used.

Question: How is a class namespace prepared
Answer: If the metaclass has no __prepare__ attribute, then the class namespace is initialised as an empty ordered mapping.
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.3.4
Answer2: If the metaclass has a __prepare__ attribute, it is called as namespace = metaclass.__prepare__(name, bases, **kwds) (where the additional keyword arguments, if any, come from the class definition).
Answer3: The namespace returned by __prepare__ is passed in to __new__
Answer4: when the final class object is created the namespace is copied into a new dict.

Question: How is a class body executed
Answer: exec(body, globals(), namespace) plus allows reference names from the current and outer scopes when the class definition occurs inside a function.
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.3.5

Question: How is a class object created
Answer: todo
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Chapter: 3
Section: 3.3.5

Variable: __class_getitem__(cls, key)
Meaning: todo: realted to type hint check
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.5
Chapter: 3
Variables: Class declaration

Syntactic sugar: o(args)
Implementation: o.__call__(o, args)
Language: python
Section: 3.6
Variables: o an object
Chapter: 3

Instruction: o.__lengtth_hint__(self)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Chapter: 3
Section: 3.7
Returns: an estimated length for the object (which may be greater or less than the actual length).
Variables: o an object
Abbreviation: operator.length_hint(o)

Syntactic sugar: o[a:]
Implementation: o[a:None]
Language: python
Section: 3.7
Variables: o an object

Syntactic sugar: o[:a]
Implementation: o[None:a]
Language: python
Section: 3.7
Variables: o an object

Syntactic sugar: o[a:b]
Implementation: o[a:b:None]
Language: python
Section: 3.7
Variables: o an object

Syntactic sugar: o[a:b:c]
Implementation: o[slice(a, b, c)]
Language: python
Section: 3.7
Variables: o an object

Syntactic sugar: o[key]
Implementation: o.__getitem__(key)
Language: python
Section: 3.7
Variables: o an object

Syntactic sugar: o[key] = value
Implementation: o.__setitem__(key, value)
Language: python
Section: 3.7
Variables: o an object

Syntactic sugar: del o[key]
Implementation: o.__delitem__(key, value)
Language: python
Section: 3.7
Variables: o an object

Variable: def __missing__(key):
Meaning: called if key is missing in a dictionnary
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.7
Variables: o an object

Instruction: it.__reversed__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.7
Returns: An iterator returning the same element than it in the reverse order
Variables: it an iterator
Abbreviation: reversed(it)

Instruction: left.__add__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left + right

Instruction: left.__sub__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left - right

Instruction: left.__mul__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left * right

Instruction: left.__matmul__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left @ right

Instruction: left.__truediv__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left / right

Instruction: left.__floordiv__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left // right

Instruction: left.__mod__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left % right

Instruction: left.__lshift__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left << right

Instruction: left.__rshift__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left >> right

Instruction: left.__and__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left & right

Instruction: left.__or__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left | right

Instruction: left.__xor__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: left ^ right

Instruction: left.__iOP__(right)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Variables: OP one of add, sub, mul, matmul, truediv, floordiv, mod, pow, lshift, rshift, and, xor, or
@ the related operation
Abbreviation: left @= right

Instruction: right.__rOP__(left)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Variables: a, b
OP one of add, sub, mul, matmul, truediv, floordiv, mod, pow, lshift, rshift, and, xor, or
@ the related operation
Abbreviation: left @= right
Assuming: left and right type are distinct
left.__rOP__ is not defined

Instruction: o.__neg__
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: -o

Instruction: o.__pos__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Abbreviation: +o

Instruction: o.__abs__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Variables: o an object
Abbreviation: abs(o)

Instruction: o.__invert__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Variables: o an object
Abbreviation: ~ o

Instruction: o.__int__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Section: 3.8
Returns: o as an integral
Variables: o an object
Abbreviation: int(o)

Instruction: foo.__index__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Chapter: 3
Section: 3.8
Returns: losslessly convert the numeric object to an integer object
Variables: o an object
Abbreviation: operator.index(foo)

Instruction: foo.__round__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Chapter: 3
Section: 3.8
Returns: foo rounded to the closer integer
Variables: o an object
Abbreviation: round(foo)

Instruction: foo.__round__(n)
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Chapter: 3
Section: 3.8
Returns: foo rounded to the closer decimal with n digits after the decimal point
Abbreviation: round(foo, n)

Instruction: foo.__ceil__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Chapter: 3
Section: 3.8
Returns: the smallest integer greater than or equal to foo
Abbreviation: ceil(foo)

Instruction: foo.__floor__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Chapter: 3
Section: 3.8
Returns: the greatest integer smaller than or equal to foo
Abbreviation: floor(foo)

Instruction: foo.__trunc__()
Page: https://docs.python.org/3/reference/datamodel.html#implementing-descriptors
Language: python
Chapter: 3
Section: 3.8
Returns: foo, rounded toward 0
Abbreviation: trunc(foo)

Page: https://www.python.org/dev/peps/pep-0343/
Syntactic sugar: with EXPR as VAR:
    BLOCK
Implementation: mgr = (EXPR)
exit = type(mgr).__exit__  # Not calling it yet
value = type(mgr).__enter__(mgr)
exc = True
try:
    try:
        VAR = value  # Only if "as VAR" is present
        BLOCK
    except:
        # The exceptional case is handled here
        exc = False
        if not exit(mgr, *sys.exc_info()):
            raise
        # The exception is swallowed if exit() returns true
finally:
    # The normal and non-local-goto cases are handled here
    if exc:
        exit(mgr, None, None, None)
Language: python

Name: metaclass confusion
Definition: The error obtained by attending to call an unbound method of a class
Page: https://docs.python.org/3/reference/datamodel.html#special-method-lookup
Example: int.__hash__() instead of type(int).__hash__(int)

Question: Restriction on special method implementation
Answer: All special methods must be implemented in the class and can't be implemented in the object.
Page: https://docs.python.org/3/reference/datamodel.html#special-method-lookup
Context: Python
Example: >>> class C:
...     pass
...
>>> c = C()
>>> c.__len__ = lambda: 5
>>> len(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'C' has no len()

Instruction: o.__aiter__(self)
Page: https://docs.python.org/3/reference/datamodel.html#asynchronous-iterators
Context: Python
Returns: an asynchronous iterator for o
Variables: O an object

Instruction: o.__anext__(self)
Page: https://docs.python.org/3/reference/datamodel.html#asynchronous-iterators
Context: Python
Returns: the next value to iterate upon
Variables: O an object
Exception: StopAsyncIteration if it halts

Instruction: o.__aenter__(self)
Page: https://docs.python.org/3/reference/datamodel.html#asynchronous-context-managers
Context: Python
Returns: An awaitable which enter the context
Variables: O an asynchronous context manager

Instruction: o.__aexit__(
  self,
  exc_type,
  exc_value,
  traceback
)
Page: https://docs.python.org/3/reference/datamodel.html#asynchronous-context-managers
Context: Python
Returns: An awaitable that exit the context manager
Variables: O an asynchronous context manager

Typ: Asynchronous context manager
Page: https://docs.python.org/3/reference/datamodel.html#asynchronous-context-managers
Function2: __aexit__(self, exc_type, exc_value, traceback)
similar to exit() in context manager, but awaitable
Context: Python
Initialization: __aenter__(self): similar to enter, but awaitable