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.
...delattr". They break down as follows (figures have some room for error because they were arrived at by partially-manual inspection): c.300 uses of plain "getattr(x, attr_name)", which could be replaced with the new syntax; c.150 uses of the 3-argument form, i.e., with the default value; these could be replaced with the 2-argument form of the new syntax (the cases break down into c.125 cases where the attribute name is a literal string, and c.25 where it's only kn...
...delattr implementation would need to track access to these attributes using the old by-name interface. If a static attribute is updated dynamically, e.g.: mod.__dict__["foo"] = 2 The implementation would need to update the array slot instead of the backup dict. Backwards compatibility The dlict will need to maintain meta-information about whether a slot is currently used or not. It will also need to maintain a pointer to the builtin namespace. When a name is not currently used in the glob...
...delattr operations now map to getitem, setitem and delitem on the celldict. The type of <module>.__dict__ and globals() is probably the only backwards incompatibility. When a module is initialized, its __builtins__ is initialized from the __builtin__ module's __dict__, which is itself a celldict. For each cell in __builtins__, the new module's __dict__ adds a cell with a NULL objptr, whose cellptr points to the corresponding cell of __builtins__. Python pseudo-code (ignoring rexec): imp...
...delattr(obj, self._name) Note that unlike the original implementation, the private attribute name is stable since it uses the name of the descriptor, and therefore instances of class A are pickleable. Example: property namespaces Python's property type takes three function arguments and a docstring argument which, though relevant only to the property, must be declared before it and then passed as arguments to the property call, e.g.: class C(object): ... def get_x(self): ... ...
...delattr(self._cls, attr) def extend(cls): return lambda: ClassNamespace(cls) class Example: pass class ExtendedExample(namespace=extend(Example)): a = 1 b = 2 c = 3 >>> Example.a, Example.b, Example.c (1, 2, 3) Rejected Design Options Calling __autodecorate__ from type.__init__ Calling the new hook automatically from type.__init__, would achieve most of the goals of this PEP. However, using that approach would mean that __autodecorate__ implementations would...