type object and the static methods and data
structures that support the Python type system in Jython (the type registry).
The class PyType contains static data that describes Python types, that are
consulted and modified through its static API (notably fromClass(Class)). The data
structures are guarded against modification by concurrent threads (or consultation while being
modified). They support construction of type objects that are visible to Python.
Bootstrapping of the type system: The first attempt to construct or get a
PyObject (or instance of a subclass of PyObject), to use the Py
class utilities, or to call PyType#fromClass(Class), causes the Jython type system to be
initialised. By the time that call returns, the type system will be in working order: any
PyTypes the application sees will be fully valid. Also, provided that the static
initialisation of the PyObject subclass in question is not obstructed for any other
reason, the instance returned will also be fully functional. Note that it is possible to refer to
C.class, and (if it is not an exposed type) to produce a PyType for it,
without causing the static initialisation of C.
This may be no less than the reader expected, but we mention it because, for classes encountered
during the bootstrapping of the type system, this guarantee is not offered. The (static)
initialisation of the type system is highly reentrant. Classes that are used by the type system
itself, and their instances, do encounter defective PyType objects. Instances
of these classes, which include mundane classes like PyNone and
PyString, may exist before their class is statically initialised in the JVM sense.
The type system has been implemented with this fact constantly in mind. The PyType
encountered is always the "right" one — the unique instance representing the Python type of
that class — but it may not be completely filled in. Debugging that enters these classes
during bootstrapping will take surprising turns. Changes to these classes should also take this
into account.
| Modifier and Type | Class and Description |
|---|---|
| protected static class | PyType.
Constants (singletons) for |
| pack-priv static class | PyType.
A thread safe, non-blocking version of Armin Rigo's mro cache. |
| pack-priv static class | PyType.
Tracks the status of merging a single base into a subclass' mro in computeMro. |
| private static interface | |
| private static class | PyType.
The class |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| protected PyType | base
__base__, the direct base type or null. |
| protected PyObject[] | bases
__bases__, the base classes. |
| protected boolean | builtin
Whether this is a builtin type. |
| protected PyObject | dict
The real, internal __dict__. |
| pack-priv boolean | |
| pack-priv boolean | hasGet
Whether this type implements descriptor __get/set/delete__ methods. |
| pack-priv boolean | |
| protected boolean | instantiable
Whether new instances of this type can be instantiated |
| private boolean | isBaseType
Whether this type allows subclassing. |
| protected PyObject[] | mro
__mro__, the method resolution. |
| protected String | name
The type's name. |
| protected boolean | needs_finalizer
Whether finalization is required for this type's instances (implements __del__). |
| protected boolean | needs_userdict
Whether this type has a __dict__. |
| protected boolean | needs_weakref
Whether this type has a __weakref__ slot (however all types are weakrefable). |
| private int | numSlots
The number of __slots__ defined by this type + bases. |
| private int | ownSlots
The number of __slots__ defined by this type itself. |
| private Set | |
| private transient ReferenceQueue | |
| private long | tp_flags
__flags__, the type's options. |
| public static final PyType | |
| protected Class | underlying_class
The Java Class that instances of this type represent (when that is a |
| private volatile boolean | usesObjectGetattribute
Whether this type's __getattribute__ is object.__getattribute__. |
| private volatile Object | versionTag
MethodCacheEntry version tag. |
| Access | Constructor and Description |
|---|---|
| protected | |
| private | |
| protected | PyType(boolean
if true, this is a proxy isProxy)Create the |
| protected | PyType(PyType subtype, Class<?> c)
As |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public PyObject | __call__(PyObject[]
all arguments to the function (including keyword arguments). args, String[] the keywords used for all keyword arguments. keywords)Overrides org. The basic method to override when implementing a callable object. |
| public void | __delattr__(String
the name which will be removed - must be an interned string . name)Overrides org. A variant of the __delattr__ method which accepts a String as the key. |
| public PyObject | __findattr_ex__(String name)
Overrides org. Attribute lookup hook. |
| protected void | |
| public void | __setattr__(String
the name whose value will be set - must be an interned string . name, PyObject the value to set this name to value)Overrides org. A variant of the __setattr__ method which accepts a String as the key. |
| public Object | __tojava__(Class<?>
the Class to convert this c)PyObject to.Overrides org. Equivalent to the Jython __tojava__ method. |
| public static void | addBuilder(Class<?>
class for which this is the builder c, TypeBuilder to register builder)Register the |
| public void | addMethod(PyBuiltinMethod meth)
Adds the given method to this type's dict under its name in its descriptor. |
| private synchronized void | |
| private static PyType | |
| private void | |
| protected void | |
| private static PyObject[] | |
| private void | |
| public void | compatibleForAssignment(PyType other, String attribute)
Ensures that the physical layout between this type and |
| protected void | computeLinearMro(Class<?> baseClass)
Fills the base and bases of this type with the type of baseClass as sets its mro to this type followed by the mro of baseClass. |
| pack-priv PyObject[] | Returns: the MRO of this classExamine the bases (which must contain no repetition) and the MROs of these bases and return the MRO of this class. |
| pack-priv PyObject[] | Returns: the MRO of this classdata structure representing the (partly processed) MROs of bases. toMerge,partial MRO (initially only this class) mro)Core algorithm for computing the MRO for "new-style" (although it's been a while) Python classes. |
| private static String | |
| private void | createAllSlots(boolean
whether a __dict__ descriptor is allowed on this type mayAddDict, boolean whether a __weakref__ descriptor is allowed on this type mayAddWeak)Create all slots and related descriptors. |
| private void | |
| private void | |
| public void | |
| public void | |
| public void | |
| private synchronized void | |
| private void | |
| public static synchronized boolean | Returns: whether bootstrapping was successfulAttempt to ensure that the that the type system has fully constructed the types necessary to
build a fully-working, exposed, |
| public static void | |
| public static void | ensureModule(PyObject
a PyObject mapping dict)Ensure dict contains a __module__, retrieving it from the current frame if it doesn't exist. |
| public PyObject | fastGetDict()
Overrides org. Returns the actual dict underlying this type instance. |
| public String | |
| private static void | |
| private static PyType | findMostDerivedMetatype(PyObject[] bases_list, PyType initialMetatype)
Finds the most derived subtype of initialMetatype in the types of bases, or initialMetatype if it is already the most derived. |
| private static int | Returns: position of first ancestor that is not equal to or ancestor of primary basetype to be investigated tp, List<PyType> list collecting all ancestors dest, Map<PyType, PyObject> map linking each type to its slots slotsMap)Used internally by |
| public static PyType | Returns: thePyType found or createdfor which the corresponding c, boolean PyType is to be foundignored hardRef)Equivalent to |
| public static PyType | |
| public PyObject | |
| public PyObject | |
| public PyObject | |
| public PyObject | |
| public PyObject | |
| public PyLong | |
| private static Class | Returns: base Java proxy Classarray of base Jython classes bases, List<Class<?>> List for collecting interfaces to interfaces)Get the most parent Java proxy Class from bases, tallying any encountered Java interfaces. |
| private PyType | getLayout()
Gets the most parent PyType that determines the layout of this type, ie it has slots or an underlying_class. |
| public PyObject | |
| public PyTuple | |
| public String | |
| public int | |
| pack-priv static Object | |
| public Class | getProxyType()
Returns the Java Class that this type inherits from, or null if this type is Python-only. |
| public PyObject | |
| pack-priv boolean | |
| pack-priv void | handleMroError(PyType.
partially processed algorithm state toMerge,output MRO (incomplete) mro)This method is called when the |
| pack-priv static boolean | |
| private void | |
| protected void | init(Set<PyJavaType>
ignored in the base implementation (see needsInners)PyJavaType#init(Set)Complete the initialisation of the |
| private static void | insertSlots(PyObject
names to be added as slots slots, Set<String> set collecting all slots dest)Used internally by |
| public PyObject | |
| protected void | |
| private static PyObject | |
| pack-priv boolean | |
| private static boolean | |
| private static boolean | isSolidBase(PyType type)
A "solid base" is a type that has an |
| public boolean | |
| public PyObject | |
| protected PyObject | Returns: found object or nullattribute name (must be interned) name)Attribute lookup for name directly through mro objects' dicts. |
| public PyObject | Returns: found object or nullattribute name (must be interned) name, PyObject[] Where in the mro the attribute was found is written to index 0 where)Attribute lookup for name through mro objects' dicts. |
| protected PyObject | Returns: found object or nullattribute name (must be interned) name, PyObject[] Where in the mro the attribute was found is written to index 0 where)Attribute lookup for name through mro objects' dicts. |
| private static String | |
| private void | |
| private void | mro_subclasses(List<Object> mroCollector)
Collects the subclasses and current mro of this type in mroCollector. |
| public final boolean | Returns: a boolean indicating whether the type implements __del__Offers public read-only access to the protected field needs_finalizer. |
| public static PyObject | |
| public void | noAttributeError(String name)
Overrides org. Raises AttributeError on type objects. |
| pack-priv void | |
| pack-priv void | |
| public void | |
| public PyObject | |
| public void | |
| public boolean | refersDirectlyTo(PyObject ob)
Implements org. Optional operation. |
| public void | removeMethod(PyBuiltinMethod meth)
Removes the given method from this type's dict or raises a KeyError. |
| protected PyObject | |
| public void | |
| public void | |
| public void | |
| private void | |
| public void | |
| pack-priv static void | setProxyAttr(PyObject obj, Object value)
Brevity for |
| private void | setupProxy(Class<?>
this type's base proxyClass baseProxyClass, List<Class<?>> a list of Java interfaces in bases interfaces)Setup the javaProxy for this type. |
| pack-priv void | |
| private static PyType | solid_base(PyType type)
Finds the first super-type of the given |
| public PyObject | |
| public String | toString()
Overrides org. Returns a string representation of the object. |
| public int | traverse(Visitproc visit, Object arg)
Implements org. Traverses all directly contained |
| private synchronized void | |
| pack-priv final PyObject | |
| pack-priv final void | |
| pack-priv void | |
| public PyObject | |
| pack-priv final PyObject | |
| public PyObject | |
| pack-priv final PyObject | |
| public PyObject | |
| pack-priv final void | |
| public final synchronized boolean | |
| public PyObject | |
| public PyObject | |
| public PyObject | |
| pack-priv static final PyObject | |
| pack-priv final void | |
| pack-priv void | |
| public final synchronized boolean | |
| public final synchronized PyObject | |
| pack-priv final PyList | |
| pack-priv final String | |
| protected boolean | useMetatypeFirst(PyObject attr)
Returns true if the given attribute retrieved from an object's metatype should be used before looking for the object on the actual object. |
| protected Object |