Top Description Inners Fields Constructors Methods
org.python.core

public abstract Class PyWrapperDescr

extends MethodDescriptor
Class Inheritance
Known Direct Subclasses
org.python.core.PyWrapperDescr.Single, org.python.core.PyWrapperDescr.Multiple
Imports
java.lang.invoke.MethodHandle, .MethodHandles, org.python.core.PyType.Flag, .Slot.Signature

A Descriptor for a particular definition in Java of one of the special methods of the Python data model (such as __sub__). The type also appears as <class 'wrapper_descriptor'>.

The owner of the descriptor is the Python type providing the definition. Type construction places a PyWrapperDescr in the dictionary of the defining PyType, against a key that is the "dunder name" of the special method it wraps. (This does not preclude client code moving it around afterwards!)

The PyWrapperDescr provides a MethodHandle for the defining method. In every Python type where a PyWrapperDescr appears as the attribute value corresponding to a special method, the handle will fill the corresponding type slot. This may happen because the type is the defining type, by inheritance, or by insertion of the PyWrapperDescr as an attribute of the type. (In the last case, the signature of the wrapped and destination slots must match.)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
PyWrapperDescr.Multiple

A PyWrapperDescr for use when the owning Python type has multiple accepted implementations.

pack-priv static class
PyWrapperDescr.Single

A PyWrapperDescr for use when the owning Python type has just one accepted implementation.

Field Summary

Modifier and TypeField and Description
pack-priv final Slot
slot

The Slot (enum) describing the generic characteristics the special method of which Descriptor#objclass provides a particular implementation.

pack-priv static final PyType

Constructor Summary

AccessConstructor and Description
pack-priv
PyWrapperDescr(PyType
the class declaring the special method
objclass
,
Slot
for the generic special method
slot
)

Construct a slot wrapper descriptor for the slot in objclass.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

result of calling the wrapped method
__call__
(Object[]
positional arguments beginning with self
args
,
String[]
of keywords in the method call
names
)

Call the wrapped method with positional arguments (the first being the target object) and optionally keywords arguments.

protected Object
protected Object
__get__(Object
object on which the attribute is sought or null
obj
,
PyType
on which this descriptor was found (may be ignored)
type
)

Implements abstract org.python.core.Descriptor.__get__.

The __get__ special method of the Python descriptor protocol, implementing obj.name or possibly type.name.
private Object
protected Object
public Object
call(Object[]
all arguments given, positional then keyword
args
,
String[]
of keyword arguments or null
names
)

Implements org.python.core.FastCall.call.

Invoke the target object with standard arguments (Object[] and String[]), providing all the argument values from the caller and names for those given by keyword.
pack-priv Object

Returns:

result of the method call
callWrapped
(Object
target object of the method call
self
,
Object[]
of the method call
args
,
String[]
of keywords in the method call
names
)

Invoke the method described by this PyWrapperDescr the given target self, and the arguments supplied.

pack-priv abstract MethodHandle

Returns:

corresponding handle (or slot.getEmpty())
getWrapped
(Class<?>
Java class of the self argument
selfClass
)

Return the handle contained in this descriptor applicable to the Java class supplied (typically that of a self argument during a call).

Inherited from org.python.core.MethodDescriptor:
checkArgscheckArgscheckArgscheckHasSelfcheckNoArgscheckNoArgstypeError

Field Detail

slotback to summary
pack-priv final Slot slot

The Slot (enum) describing the generic characteristics the special method of which Descriptor#objclass provides a particular implementation.

TYPEback to summary
pack-priv static final PyType TYPE

Constructor Detail

PyWrapperDescrback to summary
pack-priv PyWrapperDescr(PyType objclass, Slot slot)

Construct a slot wrapper descriptor for the slot in objclass.

Parameters
objclass:PyType

the class declaring the special method

slot:Slot

for the generic special method

Method Detail

__call__back to summary
public Object __call__(Object[] args, String[] names) throws TypeError, Throwable

Call the wrapped method with positional arguments (the first being the target object) and optionally keywords arguments. The arguments, in type and number, must match the signature of the special function slot.

Parameters
args:Object[]

positional arguments beginning with self

names:String[]

of keywords in the method call

Returns:Object

result of calling the wrapped method

Exceptions
TypeError:
if args[0] is the wrong type
Throwable:
from the implementation of the special method
__doc__back to summary
protected Object __doc__()
__get__back to summary
protected Object __get__(Object obj, PyType type)

Implements abstract org.python.core.Descriptor.__get__.

Doc from org.python.core.Descriptor.__get__.

The __get__ special method of the Python descriptor protocol, implementing obj.name or possibly type.name.

Parameters
obj:Object

object on which the attribute is sought or null

type:PyType

on which this descriptor was found (may be ignored)

Returns:Object

attribute value, bound object or this attribute

Annotations
@Override
__repr__back to summary
private Object __repr__()
Annotations
@SuppressWarnings:unused
__text_signature__back to summary
protected Object __text_signature__()
callback to summary
public Object call(Object[] args, String[] names) throws TypeError, Throwable

Implements org.python.core.FastCall.call.

Doc from org.python.core.FastCall.call.

Invoke the target object with standard arguments (Object[] and String[]), providing all the argument values from the caller and names for those given by keyword. If no other methods are implemented, a call to any other interface method will land here with an array of the arguments.This is to provide implementations of __call__ with a default when no more optimal call is possible.

np = args.length - names.length arguments are given by position, and the keyword arguments are {names[i]:args[np+i]}.

Parameters
args:Object[]

all arguments given, positional then keyword

names:String[]

of keyword arguments or null

Returns:Object

result of the invocation

Annotations
@Override
Exceptions
Throwable:
from the implementation
callWrappedback to summary
pack-priv Object callWrapped(Object self, Object[] args, String[] names) throws Throwable

Invoke the method described by this PyWrapperDescr the given target self, and the arguments supplied.

Parameters
self:Object

target object of the method call

args:Object[]

of the method call

names:String[]

of keywords in the method call

Returns:Object

result of the method call

Exceptions
Throwable:
from the implementation of the special method
TypeError:
if the arguments do not fit the special method
getWrappedback to summary
pack-priv abstract MethodHandle getWrapped(Class<?> selfClass)

Return the handle contained in this descriptor applicable to the Java class supplied (typically that of a self argument during a call). The Descriptor#objclass is consulted to make this determination. If the class is not an accepted implementation of objclass, an empty slot handle (with the correct signature) is returned.

Parameters
selfClass:Class<?>

Java class of the self argument

Returns:MethodHandle

corresponding handle (or slot.getEmpty())

org.python.core back to summary

pack-priv Class PyWrapperDescr.Multiple

extends PyWrapperDescr
Class Inheritance

A PyWrapperDescr for use when the owning Python type has multiple accepted implementations.

Field Summary

Modifier and TypeField and Description
protected final MethodHandle[]
wrapped

Handles for the particular implementations of a special method being wrapped.

Inherited from org.python.core.PyWrapperDescr:
slotTYPE

Constructor Summary

AccessConstructor and Description
pack-priv
Multiple(PyType
the class declaring the special method
objclass
,
Slot
for the generic special method
slot
,
MethodHandle[]
handles to the implementation of that slot
wrapped
)

Construct a slot wrapper descriptor, identifying by an array of method handles the implementation methods for the slot in objclass.

Method Summary

Modifier and TypeMethod and Description
pack-priv MethodHandle
getWrapped(Class<?>
Java class of the self argument
selfClass
)

Implements abstract org.python.core.PyWrapperDescr.getWrapped.

Return the handle contained in this descriptor applicable to the Java class supplied (typically that of a self argument during a call).
Inherited from org.python.core.PyWrapperDescr:
__call____doc____get____text_signature__callcallWrapped

Field Detail

wrappedback to summary
protected final MethodHandle[] wrapped

Handles for the particular implementations of a special method being wrapped. The method type of each is that of slot.signature.

Constructor Detail

Multipleback to summary
pack-priv Multiple(PyType objclass, Slot slot, MethodHandle[] wrapped)

Construct a slot wrapper descriptor, identifying by an array of method handles the implementation methods for the slot in objclass.

Parameters
objclass:PyType

the class declaring the special method

slot:Slot

for the generic special method

wrapped:MethodHandle[]

handles to the implementation of that slot

Method Detail

getWrappedback to summary
pack-priv MethodHandle getWrapped(Class<?> selfClass)

Implements abstract org.python.core.PyWrapperDescr.getWrapped.

Doc from org.python.core.PyWrapperDescr.getWrapped.

Return the handle contained in this descriptor applicable to the Java class supplied (typically that of a self argument during a call). The Descriptor#objclass is consulted to make this determination. If the class is not an accepted implementation of objclass, an empty slot handle (with the correct signature) is returned.

The method will check that the type of self matches Descriptor#objclass, according to its PyType#indexAccepted(Class).

Parameters
selfClass:Class<?>

Java class of the self argument

Returns:MethodHandle

corresponding handle (or slot.getEmpty())

Annotations
@Override
org.python.core back to summary

pack-priv Class PyWrapperDescr.Single

extends PyWrapperDescr
Class Inheritance

A PyWrapperDescr for use when the owning Python type has just one accepted implementation.

Field Summary

Modifier and TypeField and Description
protected final MethodHandle
wrapped

A handle for the particular implementation of a special method being wrapped.

Inherited from org.python.core.PyWrapperDescr:
slotTYPE

Constructor Summary

AccessConstructor and Description
pack-priv
Single(PyType
the class declaring the special method
objclass
,
Slot
for the generic special method
slot
,
MethodHandle
a handle to an implementation of that slot
wrapped
)

Construct a slot wrapper descriptor, identifying by a method handle the implementation method for the slot in objclass.

Method Summary

Modifier and TypeMethod and Description
pack-priv MethodHandle
getWrapped(Class<?>
Java class of the self argument
selfClass
)

Implements abstract org.python.core.PyWrapperDescr.getWrapped.

Return the handle contained in this descriptor applicable to the Java class supplied (typically that of a self argument during a call).
Inherited from org.python.core.PyWrapperDescr:
__call____doc____get____text_signature__callcallWrapped

Field Detail

wrappedback to summary
protected final MethodHandle wrapped

A handle for the particular implementation of a special method being wrapped. The method type is that of slot.signature.

Constructor Detail

Singleback to summary
pack-priv Single(PyType objclass, Slot slot, MethodHandle wrapped)

Construct a slot wrapper descriptor, identifying by a method handle the implementation method for the slot in objclass.

Parameters
objclass:PyType

the class declaring the special method

slot:Slot

for the generic special method

wrapped:MethodHandle

a handle to an implementation of that slot

Method Detail

getWrappedback to summary
pack-priv MethodHandle getWrapped(Class<?> selfClass)

Implements abstract org.python.core.PyWrapperDescr.getWrapped.

Doc from org.python.core.PyWrapperDescr.getWrapped.

Return the handle contained in this descriptor applicable to the Java class supplied (typically that of a self argument during a call). The Descriptor#objclass is consulted to make this determination. If the class is not an accepted implementation of objclass, an empty slot handle (with the correct signature) is returned.

Parameters
selfClass:Class<?>

Java class of the self argument

Returns:MethodHandle

corresponding handle (or slot.getEmpty())

Annotations
@Override