Top Description Inners Fields Constructors Methods
org.python.core

public Class PyType

extends Operations
implements DictPyObject
Class Inheritance
All Implemented Interfaces
org.python.core.DictPyObject, org.python.core.CraftedPyObject
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodHandles.Lookup, .VarHandle, java.util.ArrayList, .Arrays, .Collections, .EnumSet, .LinkedHashMap, .LinkedList, .List, .Map, org.python.base.InterpreterError, org.python.core.Exposed.Getter, .Slot.Signature

The Python type object. Type objects are normally created (when created from Java) by a call to PyType#fromSpec(Spec).

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PyType.BootstrapTask

A record used to defer the completion of a particular type object.

public static enum
PyType.Flag

Enumeration of the characteristics of a type.

public static class
PyType.Spec

A specification for a Python type.

Field Summary

Modifier and TypeField and Description
pack-priv final int
acceptedCount

The number of Java classes in classes that are acceptable as self in methods.

private PyType
base

The __base__ of this type.

private PyType[]
bases

The __bases__ of this type, which are the types named in heading of the Python class definition, or just object if none are named, or an empty array in the special case of object itself.

pack-priv final Map<Slot, Operations.BinopGrid>
binopTable

Handle arrays for in which to look up binary class-specific methods when these are provided as a supplementary implementation class.

pack-priv static final Map<Class<?>, PyType.BootstrapTask>
bootstrapTasks

Classes for which the type system has to prepare PyType objects in two stages, deferring the filling of the dictionary of the type until all classes in this set have completed their static initialisation in Java and built a PyType.

pack-priv final Class<?>[]
classes

The Java classes appearing as operands in the operations and methods of the type.

pack-priv final Class<?>
definingClass

The Java class defining operations on instances of the type.

private final Map<String, Object>
dict

The dictionary of the type is always an ordered Map.

pack-priv static final PyType[]
EMPTY_TYPE_ARRAY

An empty array of type objects

pack-priv EnumSet<PyType.Flag>
flags

Characteristics of the type, to determine behaviours (such as mutability) of instances or the type itself, or to provide quick answers to frequent questions such as "are instances data descriptors".

pack-priv final int
implCount

The number of classes in classes recognised by the run-time as implementations of the type.

private static MethodHandles.Lookup
LOOKUP

Lookup object on PyType.

private PyType[]
mro

The __mro__ of this type, that is, the method resolution order, as defined for Python and constructed by the mro() method (which may be overridden), by analysis of the __bases__.

pack-priv final String
name

Name of the type.

pack-priv static final PyType
OBJECT_TYPE

The type object of object objects.

private static final PyType[]
ONLY_OBJECT

An array containing only 'object', the bases of many types.

public static final PyType
TYPE

The type object of type objects.

private final PyType
type

Particular type of this PyType.

Inherited from org.python.core.Operations:
DERIVEDop_absop_addop_aiterop_andop_anextop_awaitop_boolop_callop_containsop_delattrop_deleteop_delitemop_divmodop_eqop_floatop_floordivop_geop_getop_getattrop_getattributeop_getitemop_gtop_hashop_iaddop_iandop_ifloordivop_imatmulop_imodop_imulop_indexop_initop_intop_invertop_iorop_isubop_iterop_itruedivop_ixorop_leop_lenop_lshiftop_ltop_matmulop_modop_mulop_neop_negop_nextop_orop_posop_powop_raddop_randop_rdivmodop_reprop_rfloordivop_rlshiftop_rmatmulop_rmodop_rmulop_rorop_rpowop_rrshiftop_rshiftop_rsubop_rtruedivop_rxorop_setop_setattrop_setitemop_strop_subop_truedivop_xorregistry

Constructor Summary

AccessConstructor and Description
private
PyType()

Partially construct a type object for type, and by side-effect the type object of its base object.

private
PyType(PyType.Spec
specification for the type
spec
)

Partially construct a type from a type specification.

Method Summary

Modifier and TypeMethod and Description
protected void
__delattr__(String
of the attribute
name
)

Slot#op_delattr has signature Signature#DELATTR and provides attribute deletion on this type object.

protected Object

Returns:

attribute value
__getattribute__
(String
of the attribute
name
)

Slot#op_getattribute has signature Signature#GETATTR and provides attribute read access on this type object and its metatype.

protected Object
protected void
__setattr__(String
of the attribute
name
,
Object
to give the attribute
value
)

Slot#op_setattr has signature Signature#SETATTR and provides attribute write access on this type object.

private void
addDefinitions(PyType.Spec
to apply
spec
)

Add methods, get-sets, members and special functions as attributes to this type, as discovered through the specification.

private static PyType

Returns:

the acceptable base
bestBase
(PyType[]
sub-classed by the new type
bases
)

Given the bases of a new class, choose the type on which a sub-class should be implemented.

pack-priv boolean

Returns:

true iff o is of a sub-type of this type
check
(Object
object to test
o
)

true iff the type of o is a Python sub-type of this (including exactly this type).

public boolean

Returns:

true iff o is exactly of this type
checkExact
(Object
object to test
o
)

true iff the Python type of o is exactly this, not a Python sub-type of this, nor just any Java sub-class of PyType.

private void
deduceFlags()

The flags field caches many characteristics of the type that we need to consult: we deduce them here.

private void
defineOperations(PyType.Spec spec)

Define the Operations objects for this type, posting them to the registry.

private void
fillDictionary(PyType.Spec
to apply
spec
)

Load the dictionary of this type with attributes discovered through the specification.

pack-priv static PyType

Returns:

the Python type of klass
fromClass
(Class<?>
to inspect
klass
)

Hides org.python.core.Operations.fromClass.

Get the Python type corresponding to the given Java class.
public static PyType

Returns:

the constructed PyType
fromSpec
(PyType.Spec
specification
spec
)

Construct a type from the given specification.

pack-priv PyType

Returns:

the base (core use only).
getBase
()

Get the __base__ of this type.

pack-priv PyType[]

Returns:

the bases as an array (core use only).
getBases
()

public final Map<Object, Object>
getDict()

Implements org.python.core.DictPyObject.getDict.

The dictionary of a type in a read-only view.
pack-priv static Object
pack-priv Class<?>
getJavaClass()

Implements abstract org.python.core.Operations.getJavaClass.

Get the (canonical) Java implementation class of this PyType object.
pack-priv PyType[]

Returns:

the MRO as an array (core use only).
getMRO
()

public String

Returns:

name of this type
getName
()

The name of this type.

pack-priv static Object
public PyType
getType()

Implements org.python.core.CraftedPyObject.getType.

The Python type of this object.
pack-priv final boolean

Returns:

whether a descriptor
hasGenericGetAttr
()

Return whether this type uses object.__getattribute__ from .

pack-priv int

Returns:

its index or -1
indexAccepted
(Class<?>
a class matching one of the accepted classes
c
)

Find the index of the given class in the accepted classes for this type.

pack-priv int

Returns:

its index or -1
indexOperand
(Class<?>
a class matching one of the operand classes
c
)

Find the index of the given class in the known operand classes for this type.

pack-priv final boolean

Returns:

whether a data descriptor
isDataDescr
()

Overrides org.python.core.Operations.isDataDescr.

Return whether an instance of this type is a data descriptor (defines __get__ and at least one of __set__ or __delete__.
pack-priv final boolean

Returns:

whether a descriptor
isDescr
()

Return whether an instance of this type is a descriptor (defines __get__).

private static boolean
isDunderName(String n)

A name has the form __A__ where A is one or more characters.

pack-priv final boolean

Returns:

whether a method descriptor
isMethodDescr
()

Overrides org.python.core.Operations.isMethodDescr.

Return whether an instance of this type defines __get__ participates in the optimised call pattern supported by Opcode311#LOAD_METHOD.
pack-priv final boolean

Returns:

whether a data descriptor
isMutable
()

Return whether special methods in this type may be assigned new meanings after type creation (or may be safely cached).

pack-priv boolean

Returns:

true if this is a sub-type of b
isSubTypeOf
(PyType
to test
b
)

Determine if this type is a Python sub-type of b (if b is on the MRO of this type).

pack-priv Object

Returns:

dictionary entry or null
lookup
(String
to look up, must be exactly a str
name
)

Look for a name, returning the entry directly from the first dictionary along the MRO containing key name.

pack-priv Object

Returns:

dictionary entry or null
lookup
(PyUnicode
to look up, must be exactly a str
name
)

Equivalent to lookup(String), accepting PyUnicode.

public static PyType

Returns:

the Python type of obj
of
(Object
to inspect
obj
)

Hides org.python.core.Operations.of.

Get the Python type of the given object obj.
private void
setAllSlots()

Set all the slots (op_*) from the entries in the dictionaries of this type and its bases.

private void
setBases(PyType[]
to set
bases
)

Set bases and deduce base.

private void
setMROfromBases()

Set the MRO, but at present only single base.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
pack-priv PyType
type(Object
subject of the enquiry
x
)

Implements abstract org.python.core.Operations.type.

Get the Python type of the object given that this is the operations object for it.
private boolean

Returns:

true if this is a sub-type of b
type_is_subtype_base_chain
(PyType
to test
b
)

Determine if this type is a Python sub-type of b by chaining through the base property.

pack-priv PyType
uniqueType()

Implements abstract org.python.core.Operations.uniqueType.

Get the unique Python type for which this is operations object.
protected void
updateAfterSetAttr(String
of the attribute modified
name
)

Called from __setattr__(String, Object) after an attribute has been set or deleted.

Inherited from org.python.core.Operations:
getIndexisIntExactregisterregister