Notice: While JavaScript is not essential for this website, your interaction with the content will be limited. Please turn JavaScript on for the full experience.
...mutable: builtin functions, function code, global variables, local variables, ... can be modified at runtime. Implement optimizations respecting the Python semantics requires to detect when "something changes", we will call these checks "guards". This PEP proposes to add a public API to the Python C API to add specialized codes with guards to a function. When the function is called, a specialized code is used if nothing changed, otherwise use the original bytecode. Even if guards help to respect...
...mutable mapping is desirable: Immutable mappings are hashable which allows their use as dictionary keys or set elements. This hashable property permits functions decorated with @functools.lru_cache() to accept immutable mappings as arguments. Unlike an immutable mapping, passing a plain dict to such a function results in error. Immutable mappings can hold complex state. Since immutable mappings can be copied by reference, transactional mutation of state can be efficiently implement...
...mutable mapping is desirable: Immutable mappings are hashable which allows their use as dictionary keys or set elements. This hashable property permits functions decorated with @functools.lru_cache() to accept immutable mappings as arguments. Unlike an immutable mapping, passing a plain dict to such a function results in error. Immutable mappings can hold complex state. Since immutable mappings can be copied by reference, transactional mutation of state can be efficiently implemented. Immutab...
...mutable [4]. Reference Implementation Thomas Wouters has checked an implementation into the Py3K branch, r53872. References [1]http://docs.python.org/reference/lexical_analysis.html#string-literals [2]http://docs.python.org/reference/lexical_analysis.html#encoding-declarations [3]http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation [4]https://mail.python.org/pipermail/python-3000/2007-February/005779.html Copyright This document has been p...
...mutable dictionary, mapping parameter names to an object representing the evaluated annotation expression There is a special key in the __annotations__ mapping, "return". This key is present only if an annotation was supplied for the function's return value. For example, the following annotation: def foo(a: 'x', b: 5 + 6, c: list) -> max(2, 9): ... would result in an __annotations__ mapping of {'a': 'x', 'b': 11, 'c': list, 'return': 9} The return key was chosen because it cannot ...
...mutable, but don't implement __hash__(); their value can change if the underlying dict is mutated. The only requirements on the underlying dict are that it implements __getitem__(), __contains__(), __iter__(), and __len__(). We don't implement .copy() -- the presence of a .copy() method suggests that the copy has the same type as the original, but that's not feasible without copying the underlying dict. If you want a copy of a specific type, like list or set, you can just pass one of the above ...
...mutable type (to allow for hashing), and one mutable type (as efficient accumulation is often necessary when working with network messages). Resolution This PEP is made obsolete by the acceptance of PEP 461, which introduces a more extended formatting language for bytes objects in conjunction with the modulo operator. References Issue #3982: support .format for bytes Mercurial project Twisted project Documentation of Python 2 formatting (str % args) Documentation of Python 2 formatting (st...
...mutable. The thinking seemed to be that having a field that was mutated after the creation of the code object made the object seem mutable, even though no other aspect of code objects changed. The view of this PEP is that the co_extra field doesn't change the fact that code objects are immutable. The field is specified in this PEP to not contain information required to make the code object usable, making it more of a caching field. It could be viewed as similar to the UTF-8 cache that string obj...
...mutable: builtin functions, function code, global variables, local variables, ... can be modified at runtime. Implementing optimizations respecting the Python semantics requires to detect when "something changes": we will call these checks "guards". The speedup of optimizations depends on the speed of guard checks. This PEP proposes to add a private version to dictionaries to implement fast guards on namespaces. Dictionary lookups can be skipped if the version does not change, which is the commo...
...mutable type and want to add some mutable state (maybe you add a default conversion to a string type), it's best to initialize the mutable state in the __init__ method and leave __new__ alone. If you want to change the constructor's signature, you often have to override both __new__ and __init__ to accept the new signature. However, most built-in types ignore the arguments to the method they don't use; in particular, the immutable types (int, long, float, complex, str, unicode, and tup...
...mutable object types, the initialization cannot be done by the tp_init() slot: this would provide the Python user with a way to change the initialization. Therefore, immutable objects typically have an empty tp_init() implementation and do all their initialization in their tp_new() slot. You may wonder why the tp_new() slot shouldn't call the tp_init() slot itself. The reason is that in certain circumstances (like support for persistent objects), it is important to be able to create an object ...
...mutable. This is similar to mutable container types such as List and Dict. Example where this is relevant: class A(TypedDict): x: Optional[int] class B(TypedDict): x: int def f(a: A) -> None: a['x'] = None b: B = {'x': 0} f(b) # Type check error: 'B' not compatible with 'A' b['x'] + 1 # Runtime error: None + 1 A TypedDict type with a required key is not consistent with a TypedDict type where the same key is a non-required key, since the latter allows keys to be deleted. ...
...mutable type that is now referred to as bytearray. Other aspects of operating in the binary domain in Python have also evolved over the course of the Python 3 series, for example with PEP 461. Motivation With Python 3 and the split between str and bytes, one small but important area of programming became slightly more difficult, and much more painful -- wire format protocols. This area of programming is characterized by a mixture of binary data and ASCII compatible segments of text (aka ASCII-...
...mutable attribute; it can be changed by user code. But trying to set it to anything that isn't a Context object or None will raise an error. Whenever we enter an generator via __next__, send, throw, or close, or enter an async generator by calling one of those methods on its __anext__, asend, athrow, or aclose coroutines, then its .context attribute is checked, and if non-None, is automatically pushed: # GeneratorType.__next__ def __next__(self): if self.context is not None: return ...
...mutable containers of mutable complex objects. Make exceptions shareable Exceptions are propagated out of run() calls, so it isn't a big leap to make them shareable in channels. However, as noted elsewhere, it isn't essential or (particularly common) so we can wait on doing that. Make RunFailedError.__cause__ lazy An uncaught exception in a subinterpreter (from run()) is copied to the calling interpreter and set as __cause__ on a RunFailedError which is then raised. That copying part invol...
...mutable numbers are supported by this hierarchy. class Complex(Number): """Complex defines the operations that work on the builtin complex type. In short, those are: conversion to complex, bool(), .real, .imag, +, -, *, /, **, abs(), .conjugate(), ==, and !=. If it is given heterogeneous arguments, and doesn't have special knowledge about them, it should fall back to the builtin complex type as described below. """ @abstractmethod def __complex__(self): ...
PEP 205 -- Weak References PEP:205 Title:Weak References Author:Fred L. Drake, Jr. <fred at fdrake.net> Status:Final Type:Standards Track Created:14-Jul-2000 Python-Version:2.1 Post-History:11-Jan-2001 Contents Motivation Caches (weak dictionaries) Circular references Aspects of the Solution Space Invalidation Presentation Proposed Solution Implementation Strategy Possible Applications Previous Weak Reference Work in Python Weak References in Java Appendix -- Dianne ...