Top Description Inners Fields Constructors Methods
org.python.core

pack-priv abstract Class PyMethodDescr

extends MethodDescriptor
Class Inheritance
Known Direct Subclasses
org.python.core.PyMethodDescr.General, org.python.core.PyMethodDescr.AbstractPositional
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, .WrongMethodTypeException, java.util.List, org.python.base.InterpreterError, .MethodKind, org.python.core.ArgumentError.Mode, .PyType.Flag, .Slot.EmptyException

Descriptor for a method defined in Java, that is to be called from Python. A PyMethodDescr is a callable object itself, and provides binding behaviour through __get__, which usually creates a PyJavaFunction.

It suits us to sub-class PyMethodDescr to express the multiplicity of implementations and to respond to the signature of the method, optimising its data flow to arguments. Instances are therefore obtained by calling fromParser.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
PyMethodDescr.AbstractPositional

Base class for methods that accept between defined maximum and minimum numbers of arguments self, that must be given by position.

private static class
PyMethodDescr.General

The implementation may have any signature supportable in Python by ArgParser.

private static class
PyMethodDescr.Multiple

A name space for sub-classes of PyMethodDescr to use for an instance method when the owning Python type has multiple accepted implementations.

private static class
PyMethodDescr.NoArgs

A method represented by NoArgs accepts no arguments after self, by position or keyword.

private static class
PyMethodDescr.O1

The implementation signature requires self and one argument, which may be supplied by ArgParser#getDefaults().

private static class
PyMethodDescr.O2

The implementation signature requires self and two arguments, which may be supplied by ArgParser#getDefaults().

private static class
PyMethodDescr.O3

The implementation signature requires self and three arguments, which may be supplied by ArgParser#getDefaults().

private static class
PyMethodDescr.Positional

A method represented by Positional only accepts arguments after self given by position.

Field Summary

Modifier and TypeField and Description
pack-priv final ArgParser
argParser

An argument parser supplied to this PyMethodDescr at construction, from Java reflection of the implementation and from annotations on it.

pack-priv final MethodHandle
method

A handle to the implementation of the function or method.

pack-priv final MethodSignature
signature

Deduced method signature (useful to have cached when constructing a PyJavaFunction).

pack-priv static final PyType

Constructor Summary

AccessConstructor and Description
protected
PyMethodDescr(PyType
the class declaring the method
objclass
,
ArgParser
describing the signature of the method
argParser
,
MethodSignature
to which to coerce the handle
signature
,
MethodHandle
handle to invoke the wrapped method or null signifying a matching empty handle.
method
)

Construct a Python method descriptor, identifying the implementation by a parser and a method handle.

Method Summary

Modifier and TypeMethod and Description
pack-priv Object

Returns:

result of calling the wrapped method
__call__
(Object[]
all arguments beginning with self
args
,
String[]
of keyword arguments
names
)

Invoke the Java method this method descriptor points to, using the standard __call__ arguments supplied, default arguments and other information described in the associated argParser for the method.

pack-priv Object

Returns:

method bound to obj or this descriptor.
__get__
(Object
target (self) of the method, or null
obj
,
PyType
ignored
type
)

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

Return the described method, bound to obj as its "self" argument, or if obj==null, return this descriptor.
pack-priv String

Returns:

name of the function or method
__name__
()

pack-priv 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.
public Object
call(Object
single argument (may be self)
self
)

Overrides default org.python.core.FastCall.call.

Call the object with arguments given by position only.
public Object
call(Object
zeroth argument (may be self)
self
,
Object
next argument
a1
)

Overrides default org.python.core.FastCall.call.

Call the object with arguments given by position only.
public Object
call(Object
zeroth argument (may be self)
self
,
Object
next argument
a1
,
Object
next argument
a2
)

Overrides default org.python.core.FastCall.call.

Call the object with arguments given by position only.
public Object
call(Object
zeroth argument (may be self)
self
,
Object
next argument
a1
,
Object
next argument
a2
,
Object
next argument
a3
)

Overrides default org.python.core.FastCall.call.

Call the object with arguments given by position only.
pack-priv abstract Object

Returns:

result of the method call
callMethod
(Object
target object of the method call
self
,
Object[]
arguments of the method call
args
,
String[]
of arguments given by keyword or null
names
)

Invoke the wrapped method handle for the given target self, and standard arguments (Object[] and String[]).

pack-priv abstract Object

Returns:

result of the method call
callMethod
(Object
target object of the method call
self
,
Object[]
arguments of the method call
args
)

Invoke the wrapped method handle for the given target self, and arguments (Object[] given only by position.

protected final void
checkSelfType(Object
to be checked
self
)

Make sure that the argument is acceptable as 'self' by checking against the MRO of PyType.of(self).

pack-priv static PyMethodDescr

Returns:

a method descriptor supporting the signature
fromParser
(PyType
owning class
objclass
,
ArgParser
argument parser (provides name etc.)
ap
,
List<MethodHandle>
method handles for the implementations
candidates
)

Construct a Python method descriptor from an ArgParser and MethodHandles for the implementation methods.

pack-priv Object
pack-priv Object
pack-priv MethodHandle

Returns:

corresponding handle (or one that throws EmptyException)
getHandle
(Object
the self argument in some call
self
)

Return the handle contained in this descriptor applicable to the Java class of a self argument during a call.

protected MethodHandle[]

Returns:

method handles aligned to objclass.clases
prepareCandidates
(MethodSignature
handle type information distilled from parser
sig
,
List<MethodHandle>
handles on which to base return
candidates
)

Construct an array of method handles, one for each accepted implementation of objclass, working from a list of candidate method handles.

protected TypeError
pack-priv Object
simple__call__(Object[] args, String[] names)

Inherited from org.python.core.MethodDescriptor:
checkArgscheckArgscheckArgscheckHasSelfcheckNoArgscheckNoArgstypeError