Top Description Inners Fields Constructors Methods
org.python.core

pack-priv final Enum Slot

extends Enum<Slot>
Class Inheritance
Static Imports
org.python.core.ClassShorthand.B, .ClassShorthand.I, .ClassShorthand.O, .ClassShorthand.OA, .ClassShorthand.S, .ClassShorthand.SA, .ClassShorthand.T, .ClassShorthand.V

This enum provides a set of structured constants that are used to refer to the special methods of the Python data model.

These are structured constants that provide not only the String method name, but also a signature, and much information used internally by the run-time system in the creation of type objects, the interpretation of code and the creation of call sites.

In principle, any Python object may support all of the special methods, through "slots" in the Python type object PyType. These slots have identical names to the corresponding constant in this enum. The "slots" in the Python type object hold pointers (MethodHandles) to their implementations in Java for that type, which of course define the behaviour of instances in Python. Where a special method is absent from the implementation of a type, a default "empty" handle is provided from the Slot constant.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Slot.EmptyException

The type of exception thrown by invoking an empty slot.

private static class
Slot.MethodNameLookup

Lookup from special method name to Slot, to support Slot#forMethodName(String).

pack-priv static enum
Slot.Signature

An enumeration of the acceptable signatures for slots in an {link Operations} object.

private static class
Slot.Util

Helpers for Slot and Signature that can be used in the constructors.

Field Summary

Modifier and TypeField and Description
pack-priv final Slot
alt

The alternate slot e.g. __radd__ in __add__.

pack-priv final String
doc

Description to use in help messages

pack-priv final String
methodName

Name of implementation method to bind e.g. "__add__".

public static final Slot
op_abs

Defines Operations#op_abs, the abs() operation, with signature Signature#UNARY.

public static final Slot
op_add

Defines Operations#op_add, the + operation, with signature Signature#BINARY.

public static final Slot
public static final Slot
op_and

Defines Operations#op_and, the & operation, with signature Signature#BINARY.

public static final Slot
public static final Slot
public static final Slot
op_bool

Defines Operations#op_bool, conversion to a truth value, with signature Signature#PREDICATE.

public static final Slot
op_call

Defines Operations#op_call, support for calling an object, with signature Signature#CALL.

public static final Slot
op_contains

Defines Operations#op_contains, the in operation, with signature Signature#BINARY_PREDICATE.

public static final Slot
op_delattr

Defines Operations#op_delattr, attribute deletion, with signature Signature#DELATTR.

public static final Slot
op_delete

Defines Operations#op_delete, descriptor __delete__, with signature Signature#DELITEM.

public static final Slot
op_delitem

Defines Operations#op_delitem, delete from index, with signature Signature#DELITEM.

public static final Slot
op_divmod

Defines Operations#op_divmod, the divmod operation, with signature Signature#BINARY.

public static final Slot
op_eq

Defines Operations#op_eq, the == operation, with signature Signature#BINARY.

public static final Slot
op_float

Defines Operations#op_float, conversion to a float value, with signature Signature#UNARY.

public static final Slot
op_floordiv

Defines Operations#op_floordiv, the // operation, with signature Signature#BINARY.

public static final Slot
op_ge

Defines Operations#op_ge, the >= operation, with signature Signature#BINARY.

public static final Slot
op_get

Defines Operations#op_get, descriptor __get__, with signature Signature#DESCRGET.

public static final Slot
op_getattr

Defines Operations#op_getattr, attribute get, with signature Signature#GETATTR.

public static final Slot
op_getattribute

Defines Operations#op_getattribute, attribute get, with signature Signature#GETATTR.

public static final Slot
op_getitem

Defines Operations#op_getitem, get at index, with signature Signature#BINARY.

public static final Slot
op_gt

Defines Operations#op_gt, the > operation, with signature Signature#BINARY.

public static final Slot
op_hash

Defines Operations#op_hash, support for object hashing, with signature Signature#LEN.

public static final Slot
op_iadd

Defines Operations#op_iadd, the += operation, with signature Signature#BINARY.

public static final Slot
op_iand

Defines Operations#op_iand, the &= operation, with signature Signature#BINARY.

public static final Slot
op_ifloordiv

Defines Operations#op_ifloordiv, the //= operation, with signature Signature#BINARY.

public static final Slot
op_imatmul

Defines Operations#op_imatmul, the @= (matrix multiply in place) operation, with signature Signature#BINARY.

public static final Slot
op_imod

Defines Operations#op_imod, the %= operation, with signature Signature#BINARY.

public static final Slot
op_imul

Defines Operations#op_imul, the *= operation, with signature Signature#BINARY.

public static final Slot
op_index

Defines Operations#op_index, conversion to an index value, with signature Signature#UNARY.

public static final Slot
op_init

Defines Operations#op_init, object __init__, with signature Signature#INIT.

public static final Slot
op_int

Defines Operations#op_int, conversion to an integer value, with signature Signature#UNARY.

public static final Slot
op_invert

Defines Operations#op_invert, the unary ~ operation, with signature Signature#UNARY.

public static final Slot
op_ior

Defines Operations#op_ior, the |= operation, with signature Signature#BINARY.

public static final Slot
op_isub

Defines Operations#op_isub, the -= operation, with signature Signature#BINARY.

public static final Slot
op_iter

Defines Operations#op_iter, get an iterator, with signature Signature#UNARY.

public static final Slot
op_itruediv

Defines Operations#op_itruediv, the /= operation, with signature Signature#BINARY.

public static final Slot
op_ixor

Defines Operations#op_ixor, the ^= operation, with signature Signature#BINARY.

public static final Slot
op_le

Defines Operations#op_le, the <= operation, with signature Signature#BINARY.

public static final Slot
op_len

Defines Operations#op_len, support for built-in len(), with signature Signature#LEN.

public static final Slot
op_lshift

Defines Operations#op_lshift, the << operation, with signature Signature#BINARY.

public static final Slot
op_lt

Defines Operations#op_lt, the < operation, with signature Signature#BINARY.

public static final Slot
op_matmul

Defines Operations#op_matmul, the @ (matrix multiply) operation, with signature Signature#BINARY.

public static final Slot
op_mod

Defines Operations#op_mod, the % operation, with signature Signature#BINARY.

public static final Slot
op_mul

Defines Operations#op_mul, the * operation, with signature Signature#BINARY.

public static final Slot
op_ne

Defines Operations#op_ne, the != operation, with signature Signature#BINARY.

public static final Slot
op_neg

Defines Operations#op_neg, the unary - operation, with signature Signature#UNARY.

public static final Slot
op_next

Defines Operations#op_next, advance an iterator, with signature Signature#UNARY.

public static final Slot
op_or

Defines Operations#op_or, the | operation, with signature Signature#BINARY.

public static final Slot
op_pos

Defines Operations#op_pos, the unary + operation, with signature Signature#UNARY.

public static final Slot
op_pow

Defines Operations#op_pow, the pow operation, with signature Signature#TERNARY.

public static final Slot
op_radd

Defines Operations#op_radd, the reflected + operation, with signature Signature#BINARY.

public static final Slot
op_rand

Defines Operations#op_rand, the reflected & operation, with signature Signature#BINARY.

public static final Slot
op_rdivmod

Defines Operations#op_rdivmod, the reflected divmod operation, with signature Signature#BINARY.

public static final Slot
op_repr

Defines Operations#op_repr, support for built-in repr(), with signature Signature#UNARY.

public static final Slot
op_rfloordiv

Defines Operations#op_rfloordiv, the reflected // operation, with signature Signature#BINARY.

public static final Slot
op_rlshift

Defines Operations#op_rlshift, the reflected << operation, with signature Signature#BINARY.

public static final Slot
op_rmatmul

Defines Operations#op_rmatmul, the reflected @ operation, with signature Signature#BINARY.

public static final Slot
op_rmod

Defines Operations#op_rmod, the reflected % operation, with signature Signature#BINARY.

public static final Slot
op_rmul

Defines Operations#op_rmul, the reflected * operation, with signature Signature#BINARY.

public static final Slot
op_ror

Defines Operations#op_ror, the reflected | operation, with signature Signature#BINARY.

public static final Slot
op_rpow

Defines Operations#op_rpow, the reflected pow operation, with signature Signature#BINARY (not Signature#TERNARY since only an infix operation can be reflected).

public static final Slot
op_rrshift

Defines Operations#op_rrshift, the reflected >> operation, with signature Signature#BINARY.

public static final Slot
op_rshift

Defines Operations#op_rshift, the >> operation, with signature Signature#BINARY.

public static final Slot
op_rsub

Defines Operations#op_rsub, the reflected - operation, with signature Signature#BINARY.

public static final Slot
op_rtruediv

Defines Operations#op_rtruediv, the reflected / operation, with signature Signature#BINARY.

public static final Slot
op_rxor

Defines Operations#op_rxor, the reflected ^ operation, with signature Signature#BINARY.

public static final Slot
op_set

Defines Operations#op_set, descriptor __set__, with signature Signature#SETITEM.

public static final Slot
op_setattr

Defines Operations#op_setattr, attribute set, with signature Signature#SETATTR.

public static final Slot
op_setitem

Defines Operations#op_setitem, set at index, with signature Signature#SETITEM.

public static final Slot
op_str

Defines Operations#op_str, support for built-in str(), with signature Signature#UNARY.

public static final Slot
op_sub

Defines Operations#op_sub, the - operation, with signature Signature#BINARY.

public static final Slot
op_truediv

Defines Operations#op_truediv, the / operation, with signature Signature#BINARY.

public static final Slot
op_xor

Defines Operations#op_xor, the ^ operation, with signature Signature#BINARY.

private MethodHandle
operandError

Handle to throw a TypeError (same signature as slot).

pack-priv final String
opName

Name to use in error messages, e.g. "+"

pack-priv final Slot.Signature
signature

Method signature to match when filling this slot.

pack-priv final VarHandle
slotHandle

Reference to field holding this slot in an Operations

Constructor Summary

AccessConstructor and Description
private
Slot(Slot.Signature
of the function to be called
signature
,
String
symbol (such as "+")
opName
,
String
implementation method (e.g. "__add__")
methodName
,
Slot
alternate slot (e.g. "op_radd")
alt
)

Constructor for enum constants.

private
Slot(Slot.Signature signature)

private
Slot(Slot.Signature signature, String opName)

private
Slot(Slot.Signature signature, String opName, Slot alt)

Method Summary

Modifier and TypeMethod and Description
private String
dunder(String methodName)

Compute corresponding double-underscore method name.

public static Slot

Returns:

the Slot corresponding, or null
forMethodName
(String
of a (possible) special method
name
)

Lookup by method name, returning null if it is not a recognised name for any slot.

pack-priv MethodHandle

Returns:

current contents of the alternate slot in t
getAltSlot
(Operations
target operations object
ops
)

Get the MethodHandle of this slot's "alternate" operation from the given operations object.

pack-priv MethodHandle

Returns:

empty method handle for this type of slot
getEmpty
()

Get the default that fills the slot when it is "empty".

pack-priv String

Returns:

conventional special method name.
getMethodName
()

Get the name of the method that, by convention, identifies the corresponding operation in the implementing class.

pack-priv MethodHandle

Returns:

throwing method handle for this type of slot
getOperandError
()

Get a handle to throw a TypeError with a message conventional for the slot.

pack-priv MethodHandle

Returns:

current contents of this slot in ops
getSlot
(Operations
target operations object
ops
)

Get the MethodHandle of this slot's operation from the given operations object.

pack-priv MethodType

Returns:

the invocation type of slots of this name.
getType
()

Return the invocation type of slots of this name.

pack-priv boolean

Returns:

true iff defined (non-empty)
isDefinedFor
(Operations
to examine for this slot
ops
)

Test whether this slot is non-empty in the given operations object.

pack-priv void
setDefinition(Operations
target Operations (or PyType).
ops
,
Object
object defining the handle to set (or null)
def
)

Set the MethodHandle of this slot's operation in the given operations object to one that calls the object given in a manner appropriate to its type.

pack-priv void
setHandle(Operations
target type object
ops
,
MethodHandle
handle value to assign
mh
)

Set the MethodHandle of this slot's operation in the given operations object.

private static InterpreterError

Returns:

exception with message filled in
slotTypeError
(Slot
that the client attempted to set
slot
,
MethodHandle
offered value found unsuitable
mh
)

Helper for Slot#setHandle(PyType, MethodHandle), when a bad handle is presented.

public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.
public static Slot
public static Slot[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf