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 order: >>> class Shake(Enum): ... vanilla = 7 ... chocolate = 4 ... cookies = 9 ... mint = 3 ... >>> for shake in Shake: ... print(shake) ... Shake.vanilla Shake.chocolate Shake.cookies Shake.mint Enumeration members are hashable, so they can be used in dictionaries and sets: >>> apples = {} >>> apples[Color.red] = 'red delicious' >>> apples[Color.green] = 'granny smith' >>> apples {<Color.red: 1>: 'red delicious...
...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 lists are written like this: what Definition lists associate a term with a definition. how The term is a one-line phrase, and the definition is one or more paragraphs or body elements, indented relative to the term. Tables Simple tables are easy and compact: ===== ===== ======= A B A and B ===== ===== ======= False False False True False False False True False True True True ===== ===== ======= There must be at least two columns in a ...
...definition of y by l()['y'] = 4 is lost. C-API Extensions to the API Two new C-API functions will be added: PyObject *PyEval_Locals(void) PyObject *PyFrame_GetLocals(PyFrameObject *f) PyEval_Locals() is equivalent to: locals(). PyFrame_GetLocals(f) is equivalent to: f.f_locals. Both functions will return a new reference. Changes to existing APIs The C-API function PyEval_GetLocals() will be deprecated. PyEval_Locals() should be used instead. The following three functions will become no-op...
...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...
...definitions for implicitly setting the attribute. This convenience has been exploited over and over again, overloading docstrings with additional semantics. For example, John Aycock has written a system where docstrings are used to define parsing rules. [1] Zope's ZPublisher ORB [2] uses docstrings to signal publishable methods, i.e. methods that can be called through the web. The problem with this approach is that the overloaded semantics may conflict with each other. For example, if we want...
...definition. In this case dispatch happens in the MRO order: >>> class Ten(Iterable, Container): ... def __iter__(self): ... for i in range(10): ... yield i ... def __contains__(self, value): ... return value in range(10) ... >>> g(Ten()) 'iterable' A similar conflict arises when subclassing an ABC is inferred from the presence of a special method like __len__() or __contains__(): >>> class Q: ... def __contains__(self, value): ....
PEP 212 -- Loop Counter Iteration PEP:212 Title:Loop Counter Iteration Author:nowonder at nowonder.de (Peter Schneider-Kamp) Status:Rejected Type:Standards Track Created:22-Aug-2000 Python-Version:2.1 Post-History: Contents Rejection Notice Introduction Motivation Loop counter iteration The Proposed Solutions Non-reserved keyword indexing Built-in functions indices and irange Methods for sequence objects Implementations Backward Compatibility Issues Copyright References Rej...
...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...
...definition: TLSBufferObject = Union[TLSWrappedSocket, TLSWrappedBuffer] class _BaseContext(metaclass=ABCMeta): @abstractmethod def __init__(self, configuration: TLSConfiguration): """ Create a new context object from a given TLS configuration. """ @property @abstractmethod def configuration(self) -> TLSConfiguration: """ Returns the TLS configuration that was used to create the context. """ class ClientContext(_BaseCont...
PEP 514 -- Python registration in the Windows registry PEP:514 Title:Python registration in the Windows registry Author:Steve Dower <steve.dower at python.org> BDFL-Delegate:Paul Moore <p.f.moore at gmail.com> Status:Active Type:Informational Created:02-Feb-2016 Post-History:02-Feb-2016, 01-Mar-2016, 18-Jul-2016 Resolution:https://mail.python.org/pipermail/python-dev/2016-July/145697.html Contents Abstract Motivation Definitions Structure Backwards Compatibility C...
...definitions for letters, digits and whitespace. If this is accepted, the cases for .ljust(), .rjust(), .center() and .split() become much stronger, and they should have default arguments as well, using an ASCII space or all ASCII whitespace (for .split()). Frequently Asked Questions Q: Why have the optional encoding argument when the encode method of Unicode objects does the same thing? A: In the current version of Python, the encode method returns a str object and we cannot change that with...
...definition. Other classes don't have a natural ordering of their attributes so you're required to use explicit names in your pattern to match with their attributes. However, it's possible to manually specify the ordering of the attributes allowing positional matching, like in this alternative definition: class Click: __match_args__ = ("position", "button") def __init__(self, pos, btn): self.position = pos self.button = btn ... The __match_args__ special attribut...
...definitions else: # Python 2 specific definitions if sys.platform == 'win32': # Windows specific definitions else: # Posix specific definitions Don't expect a checker to understand obfuscations like "".join(reversed(sys.platform)) == "xunil". Runtime or type checking? Sometimes there's code that must be seen by a type checker (or other static analysis tools) but should not be executed. For such situations the typing module defines a constant, TYPE_CHECKING, that is considered Tr...
...definition # in the `Context Variables` section. tstate = PyThreadState_Get() top_ec_node = tstate.ec top_lc = top_ec_node.lc new_top_lc = top_lc.set(self, val) tstate.ec = ec_node( prev=top_ec_node.prev, lc=new_top_lc) The contextvars.run_with_logical_context() is called, in which case the passed logical context object is appended to the execution context: def run_with_logical_context(lc, func, *args, **kwargs): tstate = PyThreadState_Get() o...
...definitions or iterable unpacking. In all these cases, we find that the syntax for sending and that for receiving 'data' are virtually identical. Assignment targets such as variables, attributes and subscripts: foo.bar[2] = foo.bar[3]; Function definitions: a function defined with def foo(x, y, z=6) is called as, e.g., foo(123, y=45), where the actual arguments provided at the call site are matched against the formal parameters at the definition site; Iterable unpacking: a, b = b, a or [a, b] ...
...definition of the template rendering semantics below The result of an interpolation template expression is an instance of this type, rather than an already rendered string - rendering only takes place when the instance's render method is called (either directly, or indirectly via __format__). The compiler will pass the following details to the interpolation template for later use: a string containing the raw template as written in the source code a parsed template tuple that allows the rendere...
...definition of a customized command followed by a whitespace character (including a newline), the customized command will be used. See below for a description of customized commands. The launcher will define a set of prefixes which are considered Unix compatible commands to launch Python, namely "/usr/bin/python", "/usr/local/bin/python", "/usr/bin/env python", and "python". If a command starts with one of these strings will be treated as a 'virtual command' and the rules described in Python Ver...
...definition. The resolution, and in fact the very definition of the meaning of "processor time", depends on that of the C function of the same name, but in any case, this is the function to use for benchmarking Python or timing algorithms. On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond. It is system-wide. ...
...definitions Integration and deployment of distributions Development and publication of distributions Metadata format Metadata files Metadata validation Core metadata Metadata version Generator Name Version Summary Source code metadata Source labels Source URL Semantic dependencies Mapping dependencies to development and distribution activities Extras Dependencies Metadata Extensions Extension versioning Required extension handling Extras (optional dependencies) Updating the metadata ...