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 Bytes and Mutable Buffer PEP:3137 Title:Immutable Bytes and Mutable Buffer Author:Guido van Rossum <guido at python.org> Status:Final Type:Standards Track Created:26-Sep-2007 Python-Version:3.0 Post-History:26-Sep-2007, 30-Sep-2007 Contents Introduction Advantages Naming Summary Literal Notations Functionality PEP 3118 Buffer API Constructors Comparisons Slicing Indexing Str() and Repr() Operators Methods Bytes and the Str Type The basestring Type Pickling Co...
...mutable(self, *args, **kws): raise TypeError('object is immutable') __setitem__ = _immutable __delitem__ = _immutable clear = _immutable update = _immutable setdefault = _immutable pop = _immutable popitem = _immutable class xdict(dict): def __freeze__(self): return imdict(self) >>> s = set([1, 2, 3]) >>> {s: 4} Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: set object...
...mutable elements. A dictionary's keys must be immutable in order to support fast, reliable lookup. While it would be easy to require set elements to be immutable, this would preclude sets of sets (which are widely used in graph algorithms and other applications). Earlier drafts of PEP 218 had only a single set type, but the sets.py implementation in Python 2.3 has two, Set and ImmutableSet. For Python 2.4, the new built-in types were named set and frozenset which are slightly less cumbersome....
...mutable objects can be truly immutable minimize performance penalty for normal Python use cases be careful when immortalizing objects that we don't actually expect to persist until runtime finalization. be careful when immortalizing objects that are not otherwise immutable __del__ and weakrefs must continue working properly Regarding "truly" immutable objects, this PEP doesn't impact the effective immutability of any objects, other than the per-object runtime state (e.g. refcount). So whether ...
...mutableDict. It is hashable if keys and values are hashable. werkzeug project has the same code: werkzeug.datastructures.ImmutableDict. ImmutableDict is used for global constant (configuration options). The Flask project uses ImmutableDict of werkzeug for its default configuration. SQLAlchemy project: sqlalchemy.util.immutabledict. It is not hashable and has an extra method: union(). immutabledict is used for the default value of parameter of some functions expecting a mapping. Example: mapper_a...
...Mutable default values Module level helper functions Discussion python-ideas discussion Support for automatically setting __slots__? Why not just use namedtuple? Why not just use typing.NamedTuple? Why not just use attrs? post-init parameters asdict and astuple function names Rejected ideas Copying init=False fields after new object creation in replace() Automatically support mutable default values Examples Custom __init__ method A complicated example Acknowledgements References Copyrigh...
...mutable buffer for full operation. Pickle consumers that use the buffer_callback and buffers arguments will have to be careful to recreate mutable buffers. When doing I/O, this implies using buffer-passing API variants such as readinto (which are also often preferable for performance). Data sharing If you pickle and then unpickle an object in the same process, passing out-of-band buffer views, then the unpickled object may be backed by the same buffer as the original pickled object. For exam...
...mutable or immutable? (Guido seems to like them to be mutable.) Copyright This document has been placed in the public domain. Source: https://github.com/python/peps/blob/master/pep-0332.txt
PEP 469 -- Migration of dict iteration code to Python 3 PEP:469 Title:Migration of dict iteration code to Python 3 Author:Nick Coghlan <ncoghlan at gmail.com> Status:Withdrawn Type:Standards Track Created:18-Apr-2014 Python-Version:3.5 Post-History:18-Apr-2014, 21-Apr-2014 Contents Abstract PEP Withdrawal Mapping iteration models Lists as mutable snapshots Iterator objects Set based dynamic views Migrating directly to Python 3 Migrating to the common subset of Python 2...
...mutable If __notes__ was mutable (e.g. a list) or even assignable, there would be no need for explicit methods to add and remove notes separate from e.g. ex.__notes__.append(note) or ex.__notes__.clear(). While we like the simplicity of this approach, it cannot guarantee that __notes__ is a sequence of strings, and thus risks failing at traceback-display time like the proposal above. Separate methods for e.g. .clear_notes() We expect that clearing or replacing notes will be extremely rare, so...
...mutable) the GIL mutable, currently protected by the GIL mutable, currently protected by some other per-interpreter lock mutable, may be used independently in different interpreters all other mutable (or effectively mutable) state not otherwise excluded below Furthermore, a number of parts of the global state have already been moved to the interpreter, such as GC, warnings, and atexit hooks. The following state will not be moved: global objects that are safely shareable, if any immutable, ofte...
...mutable state in the allocated memory of each object. Because of this, otherwise immutable objects are actually mutable. This can have a large negative impact on CPU and memory performance, especially for approaches to increasing Python's scalability.</description><author>Eric Snow <ericsnowcurrently@gmail.com>, Eddie Elizondo <eduardo.elizondorueda@gmail.com></author><guid isPermaLink="true">https://www.python.org/dev/peps/...
...MutableMapping implementation: it faithfully implements the well-known API of mutable mappings, like dict itself and other dict-like classes in the standard library. Therefore, this PEP won't rehash the semantics of most TransformDict methods. The transformation function needn't be bijective, it can be strictly surjective as in the case-insensitive example (in other words, different keys can lookup the same value): >>> d = TransformDict(str.casefold) >>> d['SomeKey'] = 5 >...
...mutable) .next() presumably just rebinds that attribute. On the other hand, another iterator whose "index" state is held as a list attribute will probably mutate the same list object when .next() executes, and therefore copies of such an iterator will not be iterable separately and independently from the original. Given this existing situation, copy.copy(it) on some iterator object isn't very useful, nor, therefore, is it at all widely used. However, there are many cases in which being able to...
...mutable sequence of integers that are in the range 0 to 255. Unlike string objects, indexing a bytes object returns an integer. Assigning or comparing an object that is not an integer to an element causes a TypeError exception. Assigning an element to a value outside the range 0 to 255 causes a ValueError exception. The .__len__() method of bytes returns the number of integers stored in the sequence (i.e. the number of bytes). The constructor of the bytes object has the following signature: ...
...MutableSequence and register these as virtual base classes for built-in types like basestring, tuple and list, so that for example the following conditions are all true: isinstance([], Sequence) issubclass(list, Sequence) issubclass(list, MutableSequence) isinstance((), Sequence) not issubclass(tuple, MutableSequence) isinstance("", Sequence) issubclass(bytearray, MutableSequence) The primary mechanism proposed here is to allow overloading the built-in functions isinstance() and issubclass(). ...
...mutable mapping implementation, rather than a full-fledged C implementation of a new mapping type integrated with the underlying data storage for optimised frames. PEP 558's fast locals proxy implementation delegates heavily to the frame value cache for the operations needed to fully implement the mutable mapping API, allowing it to re-use the existing dict implementations of the following operations: __len__ __str__ __or__ (dict union) __iter__ (allowing the dict_keyiterator type to be reused) ...
...mutable, but does provide the other features of a bytes object. The bytes object keeps track of the length of its data with a Python LONG_LONG type. Even though the current definition for PyBufferProcs restricts the length to be the size of an int, this PEP does not propose to make any changes there. Instead, extensions can work around this limit by making an explicit PyBytes_Check(...) call, and if that succeeds they can make a PyBytes_GetReadBuffer(...) or PyBytes_GetWriteBuffer call to get...
...mutable attributes Rejected because covariant subtyping of mutable attributes is not safe. Consider this example: class P(Protocol): x: float def f(arg: P) -> None: arg.x = 0.42 class C: x: int c = C() f(c) # Would typecheck if covariant subtyping # of mutable attributes were allowed. c.x >> 1 # But this fails at runtime It was initially proposed to allow this for practical reasons, but it was subsequently rejected, since this may mask some hard to spot bugs. ...
...mutable at the Python level: for example, you can't set str.myattribute = 123. Note Sharing truly immutable objects between interpreters is fine, as long as they don't provide access to mutable objects. But, every Python object has a mutable implementation detail: the reference count. Changes to the refcount are guarded by the GIL. Thus, code that shares any Python objects across interpreters implicitly depends on CPython's current, process-wide GIL. Because they are immutable and process-glob...