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.
...declaration to explicitly establish the target name as being local to the function, or else an explicit global or nonlocal declaration. TargetNameError, a new SyntaxError subclass, will be raised at compile time if no such binding or declaration is present. For example, the following code would compile and run as it does today: x = 0 x += 1 # Sets global "x" to 1 class C: x += 1 # Sets local "x" to 2, leaves global "x" alone def local_target(): x = 0 x += 1 # Sets local "x" to 1, ...
...object and type(x) is y. repr() and str() of class and instance objects now reflect the package/module in which the class is defined. Module "ni" has been removed. (If you really need it, it's been renamed to "ni1". Let me know if this causes any problems for you. Package authors are encouraged to write __init__.py files that support both ni and 1.5 package support, so the same version can be used with Python 1.4 as well as 1.5.) The thread module is now automatically inclu...
...declaration in an appropriate header file in the "Include" directory, which uses the PyAPI_FUNC() macro and PyAPI_DATA() macro, like this: PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *); PyAPI_DATA(PyTypeObject) PySuper_Type; Naming conventions Use a Py prefix for public functions; never for static functions. The Py_ prefix is reserved for global service routines like Py_FatalError; specific groups of routines (e.g. specific object type APIs) use a longer prefix, e.g. PyString_ for st...
...object. The subclass __new__ can do two things to affect the resulting object: pass different arguments to the base class __new__, and modify the resulting object after it's been created (for example to initialize essential instance variables). __new__ must return an object. There's nothing that requires that it return a new object that is an instance of its class argument, although that is the convention. If you return an existing object, the constructor call will still call its __i...
...object. The subclass __new__ can do two things to affect the resulting object: pass different arguments to the base class __new__, and modify the resulting object after it's been created (for example to initialize essential instance variables). __new__ must return an object. There's nothing that requires that it return a new object that is an instance of its class argument, although that is the convention. If you return an existing object of your class or a subclass, the constructor ...
...object): pass @overload def foo(bar:object, baz:int): pass In contrast, the following pair of implementations can never be ambiguous, because one signature always implies the other; the int/int signature is more specific than the object/object signature: def foo(bar:object, baz:object): pass @overload def foo(bar:int, baz:int): pass A signature S1 implies another signature S2, if whenever S1 would apply, S2 would also. A signature S1 is "more specific" than another signatur...
...declaration is not required and structural subtyping is verified statically. For example: interface LabeledItem { label: string; size?: int; } function printLabel(obj: LabeledItem) { console.log(obj.label); } let myObj = {size: 10, label: "Size 10 Object"}; printLabel(myObj); Note that optional interface members are supported. Also, TypeScript prohibits redundant members in implementations. While the idea of optional members looks interesting, it would complicate this proposal an...
...object-oriented languages (such as Java), and is useful for reducing the potential space of behaviors of a class, easing reasoning. Some situations where a final class or method may be useful include: A class wasn’t designed to be subclassed or a method wasn't designed to be overridden. Perhaps it would not work as expected, or be error-prone. Subclassing or overriding would make code harder to understand or maintain. For example, you may want to prevent unnecessarily tight coupling between bas...
...object is deleted -- if the assert fails, someone DECREF'ed their reference to the object without releasing it. (The rule should be that you must own a reference to the object while you've acquired the object.) For strings that might be impractical because the string object would have to grow 4 bytes to hold the counter; but the new bytes object (PEP 296) could easily implement the counter, and the array object too -- that way there will be plenty of opportunity to test proper use of the protoc...
...object-oriented programming posed a serious challenge to pattern matching. In short: in object-oriented programming, we can no longer view objects as tagged tuples. The arguments passed into the constructor do not necessarily specify the attributes or fields of the objects. Moreover, there is no longer a strict ordering of an object's fields and some of the fields might be private and thus inaccessible. And on top of this, the given object might actually be an instance of a subclass with slig...
...objects Sometimes you want to talk about class objects, in particular class objects that inherit from a given class. This can be spelled as Type[C] where C is a class. To clarify: while C (when used as an annotation) refers to instances of class C, Type[C] refers to subclasses of C. (This is a similar distinction as between object and type.) For example, suppose we have the following classes: class User: ... # Abstract base for User classes class BasicUser(User): ... class ProUser(User): .....
Version: None
Released: Feb. 23, 2014
Python 3.3.5 includes fixes for these important issues: a 3.3.4 regression in zipimport (see http://bugs.python.org/issue20621) a 3.3.4 regression executing scripts with a coding declared and Windows newlines (see http://bugs.python.org/issue20731) potential DOS using compression codecs in bytes.decode() (see http://bugs.python.org/issue19619 and http://bugs.python.org/issue20404) and also fixes quite a few other …
View Release Notes
Released: March 2, 2014
Released: March 9, 2014
...object-oriented code PEP 362, the function-signature object The new "faulthandler" module that helps diagnosing crashes The new "unittest.mock" module The new "ipaddress" module The "sys.implementation" attribute A policy framework for the email package, with a provisional (see PEP 411) policy that adds much improved unicode support for email header parsing A "collections.ChainMap" class for linking mappings to a single unit Wrappers for many mor...
...Object *module, PyModuleDef *def) Another function will be introduced to initialize a PyModuleDef object. This idempotent function fills in the type, refcount, and module index. It returns its argument cast to PyObject*, so it can be returned directly from a PyInit function: PyObject * PyModuleDef_Init(PyModuleDef *); Additionally, two helpers will be added for setting the docstring and methods on a module: int PyModule_SetDocString(PyObject *, const char *) int PyModule_AddFunctions(PyObjec...
...Object/PyVarObject: typedef struct _object { _PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt; struct _typeobject *ob_type; } PyObject; typedef struct { PyObject ob_base; Py_ssize_t ob_size; } PyVarObject; #define PyObject_HEAD PyObject ob_base; #define PyObject_VAR_HEAD PyVarObject ob_base; Types defined as fixed-size structure will then include PyObject as its first field, PyVarObject for variable-sized objects. E.g.: typedef struct { PyObject ob_base; PyObject *start, *s...
...object is created, the f_lineno attribute will be set to the line at which the function or class is defined; that is the line on which the def or class keyword appears. For modules it will be set to zero. The f_lineno attribute will be updated to match the line number about to be executed, even if tracing is turned off and no event is generated. The new co_lines() method of code objects The co_lines() method will return an iterator which yields tuples of values, each representing the line num...