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 is important. Specification Part 1: all classes have a __definition_order__ attribute __definition_order__ is a tuple of identifiers (or None) __definition_order__ is always set: during execution of the class body, the insertion order of names into the class definition namespace is stored in a tuple if __definition_order__ is defined in the class body then it must be a tuple of identifiers or None; any other value will result in TypeError classes that do not have a class defi...
...class definition, those scopes will see the trailing function or class definition rather than any other bindings for that name in the containing scope. In a very real sense, this proposal is about making it possible to override the implicit "name = <defined function or class>" name binding operation that is part of every function or class definition, specifically in those cases where the local name binding isn't actually needed. Under this PEP, an ordinary class or function definition: @d...
...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 ...
...class cannot be used in a context when an instance of the base class is expected. Renaming arguments when overloading methods can happen when the subclass has reasons to use a different choice for the parameter name that is more appropriate for the specific domain of the subclass (e.g., when subclassing Mapping to implement a DNS lookup cache, the derived class may not want to use the generic argument names ‘key’ and ‘value’ but rather ‘host’ and ‘address’). Having this function definition with ...
...definitions, a script to convert C source code containing type definitions will be provided [3]. References [1](1, 2) "python3 module definition file": http://svn.python.org/projects/python/branches/pep-0384/PC/python3.def [2]"PEP 384 branch": http://svn.python.org/projects/python/branches/pep-0384/ [3]"ABI type conversion script": http://svn.python.org/projects/python/branches/pep-0384/Tools/scripts/abitype.py Copyright This document has been placed in the public domain. So...
...class definition, the name bindings that occur in the class block are not visible to enclosed functions.) A class definition is an executable statement that may contain uses and definitions of names. These references follow the normal rules for name resolution. The namespace of the class definition becomes the attribute dictionary of the class. The following operations are name binding operations. If they occur within a block, they introduce new local names in the current block unless there i...
PEP 3152 -- Cofunctions PEP:3152 Title:Cofunctions Author:Gregory Ewing <greg.ewing at canterbury.ac.nz> Status:Rejected Type:Standards Track Created:13-Feb-2009 Python-Version:3.3 Post-History: Contents Abstract Rejection Specification Cofunction definitions Cocalls New builtins, attributes and C API functions Motivation and Rationale Prototype Implementation Copyright Abstract A syntax is proposed for defining and calling a special type of generator called a 'co...
...class 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 =...
...classmethod(foo) with an alternative that places the decoration in the function's declaration: @classmethod @synchronized(lock) def foo(cls): pass Modifying classes in this fashion is also possible, though the benefits are not as immediately apparent. Almost certainly, anything which could be done with class decorators could be done using metaclasses, but using metaclasses is sufficiently obscure that there is some attraction to having an easier way to make simple modifications to classe...
...class) the actual metaclass is then determined based on the parent classes. It is notable that only the actual metaclass is inherited - a factory function used as a metaclass hook sees only the class currently being defined, and is not invoked for any subclasses. In Python 3, the metaclass hint is provided using the metaclass=Meta keyword syntax in the class header. This allows the __prepare__ method on the metaclass to be used to create the locals() namespace used during execution of the class...
...class MyClass: ... my_instance = MyClass() def my_function(self): ... # Assign to class attribute MyClass.my_function = my_function # Or assign to instance attribute my_instance.my_function = my_function While this isn't usually an inconvenience, using dot notation to assign directly in the function's header would greatly simplify this: class MyClass: ... my_instance = MyClass() # Assign to class attribute def MyClass.my_function(self): ... # Or assign to instance attrib...
...class definition: a class attribute. At the top level of the "__init__" method definition of a class: an instance attribute. Instance attributes assigned in other methods are assumed to be implementation details. (@@@ __new__ methods?) A function attribute assignment at the top level of a module or class definition. Since each of the above contexts are at the top level (i.e., in the outermost suite of a definition), it may be necessary to place dummy assignments for attributes assigned condit...
...definition is actually a generator) Explaining Decorator Clause Evaluation and Application The standard explanation of decorator clause evaluation and application has to deal with the idea of hidden compiler variables in order to show steps in their order of execution. The given statement allows a decorated function definition like: @classmethod def classname(cls): return cls.__name__ To instead be explained as roughly equivalent to: classname = .d1(classname) given: d1 = classmetho...
...classes, localns can be composed by chaining vars of the given class and its base classes (in the method resolution order). Since slots can only be filled after the class was defined, we don't need to consult them for this purpose. Runtime annotation resolution and class decorators Metaclasses and class decorators that need to resolve annotations for the current class will fail for annotations that use the name of the current class. Example: def class_decorator(cls): annotations = get_ty...
...class definitions (except the one defining the metaclass) continue to fail with a TypeError as superfluous class arguments are passed: class MyMeta(type): pass class MyClass(metaclass=MyMeta, otherarg=1): pass MyMeta("MyClass", (), otherargs=1) import types types.new_class("MyClass", (), dict(metaclass=MyMeta, otherarg=1)) types.prepare_class("MyClass", (), dict(metaclass=MyMeta, otherarg=1)) A metaclass defining only a __new__ method which is interested in keyword arguments now doe...
...classes class M1(type): ... class M2(M1): ... class M3(M2): ... class M4(type): ... # Regular classes class C1: __metaclass__ = M1 class C2(C1): __metaclass__ = M2 class C3(C1, C2): __metaclass__ = M3 class D(C2, C3): __metaclass__ = M1 class C4: __metaclass__ = M4 class E(C3, C4): pass For class C2, the constraint is satisfied because M2 is a subclass of M1. For class C3, it is satisfied because M3 is a subclass of both M1 and M2. For class D,...
...classes are more accessible and less dangerous. Terminology-wise, a metaclass is simply "the class of a class". Any class whose instances are themselves classes, is a metaclass. When we talk about an instance that's not a class, the instance's metaclass is the class of its class: by definition, x's metaclass is x.__class__.__class__. But when we talk about a class C, we often refer to its metaclass when we mean C.__class__ (not C.__class__.__class__, which would be a meta-metaclass; th...
...definitions/requirementVersion" }, { "$ref": "#/definitions/requirementTable" }, { "title": "Multiple specifications", "type": "array", "items": { "$ref": "#/definitions/requirementTable" }, "minLength": 1 } ] }, "optionalRequirementTable": { ...