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.
...definition namespace. After the execution completes, the definition namespace is copied into a new dict. Then the original definition namespace is discarded. The new copy is stored away as the class's namespace and is exposed as __dict__ through a read-only proxy. The class attribute definition order is represented by the insertion order of names in the definition namespace. Thus, we can have access to the definition order by switching the definition namespace to an ordered mapping, such as c...
...definition and C extension ABI, and the desire to get new features (most notably standard library updates) into user's hands more quickly. With the standard library release cycle decoupled (to some degree) from that of the core language definition, it provides an opportunity to actually slow down the rate of change in the language definition. The language moratorium for Python 3.2 effectively slowed that cycle down to more than 3 years (3.1: June 2009, 3.3: August 2012) without causing any major...
...module. With sys.implementation the various implementations would explicitly set the values in their own version of the sys module. Another concern is that the platform module is part of the stdlib, which ideally should minimize implementation details such as would be moved to sys.implementation. Any overlap between sys.implementation and the platform module would simply defer to sys.implementation (with the same interface in platform wrapping it). Cache Tag Generation in Frozen Importlib PEP ...
...module initialization -- PyModule_AddObject(), PyModule_AddIntConstant(), and PyModule_AddStringConstant(). Cleaned up definition of NULL in C source code; all definitions were removed and add #error to Python.h if NULL isn't defined after #include of stdio.h. Py_PROTO() macros that were removed in 2.0b1 have been restored for backwards compatibility (at the source level) with old extensions. A wrapper API was added for signal() and sigaction(). Instead of either func...
...definition How can an inexperienced user validate a definition like os.stat? Simply by changing os.stat to os_stat, defining missing converters and pasting the definition into the Python interactive interpreter! In fact, a converters.py module could be auto-generated from converters.h. Reference implementation A reference implementation is available at issue 16612. Since this PEP was written under time constraints and the author is unfamiliar with the PLY toolchain, the software is written in ...
...module programmatically, by importing the module and inspecting an attribute. Classic Python distutils setup() functions [3] describe a version argument where the release's version number can be specified. PEP 8 describes the use of a module attribute called __version__ for recording "Subversion, CVS, or RCS" version strings using keyword expansion. In the PEP author's own email archives, the earliest example of the use of an __version__ module attribute by independent module developers dates...
...module-level binding to next [4] and found that it would be "ugly and slow". Instead, the translation tool will emit warnings upon detecting such a binding. Collin has proposed warnings for the following conditions [5]: Module-level assignments to next. Module-level definitions of a function named next. Module-level imports of the name next. Assignments to __builtin__.next. Approval This PEP was accepted by Guido on March 6, 2007 [5]. Implementation A patch with the necessary changes (ex...
...module started to be widely used. There are three main points of concern: performance of the typing module, metaclass conflicts, and the large number of hacks currently used in typing. Performance The typing module is one of the heaviest and slowest modules in the standard library even with all the optimizations made. Mainly this is because subscripted generic types (see PEP 484 for definition of terms used in this PEP) are class objects (see also [1]). There are three main ways how the perform...
...modules with commented debug output or modules where debug output should be added. For example: urllib Finally possibly some modules should be extended to provide more debug information. Doubtful Modules Listed here are modules that the community will propose for addition to the module list and modules that the community say should be removed from the module list. tabnanny (check) Guidelines for Logging Usage Also we can provide some recommendation to authors of library modules so they ...
...definition, a function definition or as first string literal in a module. The string literals are added to the objects in question under the __doc__ attribute and are from then on available for introspection tools which can extract the contained information for help, debugging and documentation purposes. Docstrings appearing in locations other than the ones mentioned are simply ignored and don't result in any code generation. Here is an example: class C: "class C doc-string" a = 1 ...
...module for a boolean attribute manylinux1_compatible, if the tag version is manylinux2010 or manylinux_2_12 exactly, then we also check the module for a boolean attribute manylinux2010_compatible, and if the tag version is manylinux2014 or manylinux_2_17 exactly, then we also check the module for a boolean attribute manylinux2014_compatible. If both the new and old attributes are defined, then manylinux_compatible takes precedence. Here's some example code. You don't have to actually use this co...
...module and class level code without polluting the resulting namespaces. The intent is that the relationship between a given clause and a separate function definition that performs the specified operation will be similar to the existing relationship between an explicit while loop and a generator that produces the same sequence of operations as that while loop. The specific proposal in this PEP has been informed by various explorations of this and related concepts over the years (e.g. [1], [2], [3...
...module to the standard library, with the suggested name secrets. This module will contain a set of ready-to-use functions for common activities with security implications, together with some lower-level primitives. The suggestion is that secrets becomes the go-to module for dealing with anything which should remain secret (passwords, tokens, etc.) while the random module remains backward-compatible. API and Implementation This PEP proposes the following functions for the secrets module: Func...
...definition above will bind flatten to whatever it was previously bound to. The second will do the same, if it was already bound to the when decorator's first argument. If flatten is unbound or bound to something else, it will be rebound to the function definition as given. The last two definitions above will always bind flatten_basestring to the function definition as given. Using this approach allows you to both give a method a descriptive name (often useful in tracebacks!) and to reuse the ...
...module, rather than using numeric timestamps and the time module API. Moreover, using a dedicated class allows to enable desirable behaviours by default, for example the case insensitivity of Windows paths. Proposal Class hierarchy The pathlib module implements a simple hierarchy of classes: +----------+ | | ---------| PurePath |-------- | | | | | +----------+ | | | ...
...definition, and try to fathom ``the type of the base class is callable.'' (Types are not classes, by the way. See questions 4.2, 4.19 and in particular 6.22 in the Python FAQ for more on this topic.) The base class is B; this one's easy. Since B is a class, its type is ``class''; so the type of the base class is the type ``class''. This is also known as types.ClassType, assuming the standard module types has been imported. Now is the type ``class'' callable? No, beca...
...definition syntax with typing.TypedDict as the sole base class: from typing import TypedDict class Movie(TypedDict): name: str year: int Movie is a TypedDict type with two items: 'name' (with type str) and 'year' (with type int). A type checker should validate that the body of a class-based TypedDict definition conforms to the following rules: The class body should only contain lines with item definitions of the form key: value_type, optionally preceded by a docstring. The syntax fo...
...Definitions The Python class definitions for the standard exceptions are imported from the standard module "exceptions". You can't change this file thinking that the changes will automatically show up in the standard exceptions; the builtin module expects the current hierarchy as defined in exceptions.py. Details on the standard exception classes are available in the Python library reference manual's entry for the exceptions module. Changes to raise The raise statement has b...
...module. The curses module was in the middle of a transformation to a package, so the final form was adopted. Mechanism The release will be created as a branch from the development tree rooted at CNRI's close of business on 16 May 2000. Patches required from more recent checkins will be merged in by moving the branch tag on individual files whenever possible in order to reduce mailing list clutter and avoid divergent and incompatible implementations. The branch tag is "cnri-16-start". Patches...
...module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() The problem is that internally, Python implicitly expands this chained comparison into the form: >>> 0 < increasing and increasing < 4 Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() And NumPy only permits implicit coercion to...