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.
...pattern for handling such cases is to store the global state in global or thread-local storage, and then use with blocks to limit modifications of this global state to a single dynamic scope. Examples where this pattern is used include the standard library's warnings.catch_warnings and decimal.localcontext, NumPy's numpy.errstate (which exposes the error-handling settings provided by the IEEE 754 floating point standard), and the handling of logging context or HTTP request context in many server...
...patterned after the footnote notion in setext but is easier on the eyes. For example, "Pythonland" will be marked as a hyper-references to Python.org. If no matching trailing reference is found then nothing is done.
...patterns, which in code makes it easier to read and reason about. Improvements in concurrency, fault handling, testing, and debugging provide developers with the opportunity to create more robust and secure applications. Going forward, Python 3 will be the only major version of CPython that is actively maintained for bugs and security issues. Users are urged to migrate to a supported version of Python 3 in order to benefit from its many improvements, as well as to avoid potential security vul...
...patterns that are difficult or impossible to express as a library. Macros can express those patterns in a more concise and less error-prone way. Trialing new language features It is possible to demonstrate potential language extensions using macros. For example, macros would have enabled the with statement and yield from expression to have been trialed. Doing so might well have lead to a higher quality implementation at first release, by allowing more testing before those features were include...
...pattern has precedent in e.g. invalidation of an @functools.cached_property, or any other descriptor with a deleter, and is sufficient for library code to implement whatever pattern is desired. Subclass Exception and add note support downstream Traceback printing is built into the C code, and reimplemented in pure Python in traceback.py. To get err.__notes__ printed from a downstream implementation would also require writing custom traceback-printing code; while this could be shared between pr...
...patterns, you can browse the ActiveState Python Cookbook Looking for Something Specific? If you want to know whether a particular application, or a library with particular functionality, is available in Python there are a number of possible sources of information. The Python web site provides a Python Package Index (also known as the Cheese Shop, a reference to the Monty Python script of that name). There is also a search page for a number of sources of Python-related information. Failing that...
...pattern, and MUST raise an error if the pattern contains invalid glob syntax. MUST include all files matched by at least one listed pattern in all distribution archives. MAY exclude files matched by glob patterns that can be unambiguously determined to be backup, temporary, hidden, OS-generated or VCS-ignored. MUST list each matched file path under a License-File field in the core metadata. SHOULD issue a warning and MAY raise an error if no files are matched. MAY issue a warning if any individu...
...patterns. This PEP proposes a standard Python API and provides a reference module implementation which allows for consistent handling of IEEE 754 special values on all supported platforms. API Definition Constants NaN Non-signalling IEEE 754 "Not a Number" value PosInf IEEE 754 Positive Infinity value NegInf IEEE 754 Negative Infinity value Functions isNaN(value) Determine if the argument is an IEEE 754 NaN (Not a Number) value. isPosInf(value) Determine if the argument is an IEEE 754 po...
...patterns arise in the structure of the functions rather than the actual sequence of statements. For example, many functions acquire a lock, execute some code specific to that function, and unconditionally release the lock. Repeating the locking code in every function that uses it is error prone and makes refactoring difficult. Block statements provide a mechanism for encapsulating patterns of structure. Code inside the block statement runs under the control of an object called a block iterato...
...patterns (one for positive numbers and an optional one for negatives) such as: "#,##0.00;(#,##0.00)". It allows arbitrary groupings including hundreds and ten-thousands and uneven groupings. The special pattern characters are non-localized (using a DOT for a decimal separator and a COMMA for a grouping separator). The user can supply an alternate set of symbols using the formatter's DecimalFormatSymbols object. Alternative Proposal (from Eric Smith, originally called Proposal II) Make both t...
...patterns and strings in intuitive ways, and it no longer had any way to guess what, for example, r"\x123456" should mean as a pattern: is it asking to match the 8-bit character \x56 or the Unicode character \u3456? There are hacky ways to guess, but it doesn't end there. The ISO C99 standard also introduces 8-digit \U12345678 escapes to cover the entire ISO 10646 character space, and it's also desired that Python 2 support that from the start. But then what are \x escapes supposed to mean? Do...
...pattern as for __getattribute__ applies, where you call the base class __setattr__ to do the actual work. Here's an example: class C(object): def __setattr__(self, name, value): if hasattr(self, name): raise AttributeError, "attributes are write-once" object.__setattr__(self, name, value) C++ programmers may find it useful to realize that this form of subtyping in Python is implemented very similarly to single-inheritance subc...
...pattern as for __getattribute__ applies, where you call the base class __setattr__ to do the actual work. Here's an example: class C(object): def __setattr__(self, name, value): if hasattr(self, name): raise AttributeError, "attributes are write-once" object.__setattr__(self, name, value) C++ programmers may find it useful to realize that this form of subtyping in Python is implemented very similarly to single-inheritance subclassing in C++, with...
...pattern seems to be emerging: almost all these uses of metaclasses (except for Enum, which is probably more cute than useful) mostly work by placing wrappers around method calls. An obvious problem with that is that it's not easy to combine the features of different metaclasses, while this would actually be quite useful: for example, I wouldn't mind getting a trace from the test run of the Synch module, and it would be interesting to add preconditions to it as well. This needs more rese...
...Pattern is safe and all is right with the world. Copyright This document has been placed in the public domain. Source: https://github.com/python/peps/blob/master/pep-0666.txt
...Pattern matching Another possibility would be to introduce an advanced pattern matching syntax when catching exceptions. For example: try: os.remove(filename) except OSError as e if e.errno == errno.ENOENT: pass Several problems with this proposal: it introduces new syntax, which is perceived by the author to be a heavier change compared to reworking the exception hierarchy it doesn't decrease typing effort significantly it doesn't relieve the programmer from the burden of having to ...
...pattern expressed in the Python grammar by "NAME trailer*", using the definitions in Grammar/Grammar.) Any complete Python expression enclosed in curly braces. Two dollar-signs ("$$") are replaced with a single "$". Examples Here is an example of an interactive session exhibiting the expected behaviour of this feature. >>> a, b = 5, 6 >>> print $'a = $a, b = $b' a = 5, b = 6 >>> $u'uni${a}ode' u'uni5ode' >>> print $'\$a' 5 >>> print $r'\$a' \5 >...
...Pattern Matching PEP 644, Require OpenSSL 1.1.1 or newer PEP 624, Remove Py_UNICODE encoder APIs PEP 597, Add optional EncodingWarning Copyright This document has been placed in the public domain. Source: https://github.com/python/peps/blob/master/pep-0619.rst