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.
...issubclass(D, C) returns true iff class D is derived from class C, directly or indirectly. issubclass(C, C) always returns true. Both arguments must be class objects. isinstance(x, C) returns true iff x is an instance of C or of a (direct or indirect) subclass of C. The first argument may hyave any type; if x is not an instance of any class, isinstance(x, C) always returns false. The second argument must be a class object. Sequence Unpacking Previous Python versions...
...issubclass(). (Yet. It was done to issubclass() in Python 2.3.) Introspecting instances of built-in types For instances of built-in types (and for new-style classes in general), x.__class__ is now the same as type(x): >>> type([]) <type 'list'> >>> [].__class__ <type 'list'> >>> list <type 'list'> >>> isinstance([], list) 1 >>> isinstance([], dict) 0 >>> isinstance([], object) 1 >>> In classic Python, the method names of lists were available as the __m...
...issubclass(x.__class__, X) but not issubclass(type(x), X). isinstance(x, X): if X is a new-style class, this is now equivalent to issubclass(type(x), X) or issubclass(x.__class__, X). Previously only type(x) was tested. (For classic classes this was already the case.) compile(), eval() and the exec statement now fully support source code passed as unicode strings. int subclasses can be initialized with longs if the value fits in an int. See SF bug #683467. long(string, base) takes time linear ...
...issubclass(M, M1) and issubclass(M, M2). (This is because a method of B1 should be able to call a meta-method defined in M1 on self.__class__, even when self is an instance of a subclass of B1.) The metaclasses book describes a mechanism whereby a suitable metaclass is automatically created, when necessary, through multiple inheritance from M1 and M2. In Python 2.2, I have chosen a simpler approach which raises an exception if the metaclass constraint is not satisfied; it is up to th...
...issubclass() by 50-70%, so as to match Python 2.5 speed despite the __instancecheck__ / __subclasscheck__ mechanism. In the process, fix a bug where isinstance() and issubclass(), when given a tuple of classes as second argument, were looking up __instancecheck__ / __subclasscheck__ on the tuple rather than on each type object. Issue #3663: Py_None was decref'd when printing SyntaxErrors. Issue #3651: Fix various memory leaks when using the buffer interface, or when the "s#" code of Py...
...IsSubclass() implement isinstance() and issubclass(). Py_BuildValue() now has a "D" conversion to create a Python complex number from a Py_complex C value. Extensions types which support weak references must now set the field allocated for the weak reference machinery to NULL themselves; this is done to avoid the cost of checking each object for having a weakly referencable type in PyObject_INIT(), since most types are not weakly referencable. PyFrame_FastToLocals() and PyFrame_LocalsT...
...issubclass() to the recursion limit of the interpreter. Fixes bug #858016 . Optimized dict iterators, creating separate types for each and having them reveal their length. Also optimized the methods: keys(), values(), and items(). Implemented a newcode opcode, LIST_APPEND, that simplifies the generated bytecode for list comprehensions and further improves their performance (about 35%). Implemented rich comparisons for floats, which seems to make comparisons involving NaNs somewhat less surpri...
If you didn't find what you need, try your search in the Python language documentation.