Top Description Fields Constructors Methods
org.python.core

pack-priv Class Callables

extends Abstract
Class Inheritance
Imports
java.lang.invoke.MethodHandle, java.util.Arrays, .Map, .Map.Entry

Compare CPython Objects/call.c: Py_Object_*.

Field Summary

Modifier and TypeField and Description
pack-priv static final String
private static final String[]
pack-priv static final String
pack-priv static final String
Inherited from org.python.core.Abstract:
NOT_ITERABLENOT_MAPPING

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static Object

Returns:

the return from the call to the object
call
(Object
target
callable
,
Object[]
all the arguments (position then keyword)
args
,
String[]
of the keyword arguments
names
)

Call an object with the standard __call__ protocol, that is, with an array of all the arguments, those given by position, then those given by keyword, and an array of the keywords in the same order.

pack-priv static Object

Returns:

the return from the call to the object
call
(Object
target
callable
,
PyTuple
positional arguments
argTuple
,
PyDict
keyword arguments
kwDict
)

Call an object with the classic CPython call protocol, that is, with a tuple of arguments given by position and a dictionary of key-value pairs providing arguments given by keyword.

pack-priv static Object

Returns:

the return from the call to the object
call
(Object
target
callable
)

Call an object with no arguments.

pack-priv static Object

Returns:

the return from the call to the object
callEx
(Object
target
callable
,
Object
positional arguments
args
,
Object
keyword arguments
kwargs
)

Call an object with the CPython call protocol as supported in the interpreter CALL_FUNCTION_EX opcode, that is, an argument tuple (or iterable) and keyword dictionary (or iterable of key-value pairs), which may be built by code at the opcode site.

pack-priv static Object

Returns:

the return from the call to the object
callFunction
(Object
target
callable
,
Object...
positional arguments
args
)

Call an object with positional arguments supplied from Java as Objects.

pack-priv static Object

Returns:

result of call
callMethod
(Object
target of the method invocation
obj
,
String
identifying the method
name
,
Object...
positional arguments
args
)

Resolve a name within an object and then call it with the given positional arguments supplied from Java.

public static TypeError

Returns:

exception to throw
keywordTypeError
(Object
actual object offered as a keyword
kwname
)

Create a TypeError with a message along the lines "keywords must be strings, not 'X'" giving the type X of name.

pack-priv static String[]

Returns:

the names as an array
namesArray
(PyTuple
(keyword) names to convert
kwnames
)

Convert a tuple of names to an array of Java String.

pack-priv static PyDict

Returns:

dictionary or null if kwnames==null
stackAsDict
(Object[]
positional and keyword arguments
stack
,
int
position of arguments in the array
start
,
int
number of positional arguments
nargs
,
PyTuple
tuple of names (may be null if empty)
kwnames
)

Return a dictionary containing the last len(kwnames) elements of the slice stack[start:start+nargs].

pack-priv static PyTuple

Returns:

names of keyword arguments
unpackDict
(Object[]
positional arguments
args
,
Map<Object, Object>
keyword arguments (normally PyDict)
kwargs
,
Object[]
to receive positional and keyword arguments, must be sized args.length + kwargs.size().
stack
)

Convert classic call arguments to an array and names of keywords to use in the CPython-style vector call.

pack-priv static Object

Returns:

the return from the call to the object
vectorcall
(Object
target
callable
,
Object[]
positional and keyword arguments
stack
,
int
position of arguments in the array
start
,
int
number of positional and keyword arguments
nargs
,
PyTuple
names of keyword arguments or null
kwnames
)

Call an object with the vector call protocol with some arguments given by keyword.

pack-priv static Object

Returns:

the return from the call to the object
vectorcall
(Object
target
callable
,
Object[]
positional and keyword arguments (the stack)
stack
,
int
position of arguments in the array
start
,
int
number of positional and keyword arguments
nargs
)

Call an object with the vector call protocol with no arguments given by keyword.

Inherited from org.python.core.Abstract:
argumentTypeErrorargumentTypeErrorattributeNameTypeErrorattrMustBeattrMustBeStringbadInternalCallcantSetAttributeErrordelAttrdelAttrgetAttrgetAttrgetIteratorgetIteratorhashimpossibleArgumentErrorindexOutOfRangeindexTypeErrorindexTypeErrorisTrueiterableCheckiteratorChecklookupAttrlookupAttrmandatoryAttributeErrormandatoryAttributeOnTypenextnoAttributeErrornoAttributeOnTypereadonlyAttributeErrorreadonlyAttributeOnTyperecursiveIsSubclassreprrequiredTypeErrorreturnDeprecationreturnTypeErrorrichComparerichCompareBoolrichCompareBoolsetAttrsetAttrstrtojavatypeError

Field Detail

ATTR_NOT_CALLABLEback to summary
pack-priv static final String ATTR_NOT_CALLABLE
NO_KEYWORDSback to summary
private static final String[] NO_KEYWORDS
OBJECT_NOT_CALLABLEback to summary
pack-priv static final String OBJECT_NOT_CALLABLE
OBJECT_NOT_VECTORCALLABLEback to summary
pack-priv static final String OBJECT_NOT_VECTORCALLABLE

Constructor Detail

Callablesback to summary
private Callables()

Method Detail

callback to summary
pack-priv static Object call(Object callable, Object[] args, String[] names) throws TypeError, Throwable

Call an object with the standard __call__ protocol, that is, with an array of all the arguments, those given by position, then those given by keyword, and an array of the keywords in the same order. Therefore np = args.length - names.length arguments are given by position, and the keyword arguments are args[np:] named by names[:].

Parameters
callable:Object

target

args:Object[]

all the arguments (position then keyword)

names:String[]

of the keyword arguments

Returns:Object

the return from the call to the object

Exceptions
TypeError:
if target is not callable
Throwable:
for errors raised in the function
callback to summary
pack-priv static Object call(Object callable, PyTuple argTuple, PyDict kwDict) throws TypeError, Throwable

Call an object with the classic CPython call protocol, that is, with a tuple of arguments given by position and a dictionary of key-value pairs providing arguments given by keyword.

Parameters
callable:Object

target

argTuple:PyTuple

positional arguments

kwDict:PyDict

keyword arguments

Returns:Object

the return from the call to the object

Exceptions
TypeError:
if target is not callable
Throwable:
for errors raised in the function
callback to summary
pack-priv static Object call(Object callable) throws Throwable

Call an object with no arguments.

Parameters
callable:Object

target

Returns:Object

the return from the call to the object

Exceptions
Throwable:
for errors raised in the function
TypeError:
if target is not callable
callExback to summary
pack-priv static Object callEx(Object callable, Object args, Object kwargs) throws TypeError, Throwable

Call an object with the CPython call protocol as supported in the interpreter CALL_FUNCTION_EX opcode, that is, an argument tuple (or iterable) and keyword dictionary (or iterable of key-value pairs), which may be built by code at the opcode site.

Parameters
callable:Object

target

args:Object

positional arguments

kwargs:Object

keyword arguments

Returns:Object

the return from the call to the object

Exceptions
TypeError:
if target is not callable
Throwable:
for errors raised in the function
callFunctionback to summary
pack-priv static Object callFunction(Object callable, Object... args) throws Throwable

Call an object with positional arguments supplied from Java as Objects.

Parameters
callable:Object

target

args:Object[]

positional arguments

Returns:Object

the return from the call to the object

Exceptions
Throwable:
for errors raised in the function
TypeError:
if target is not callable
callMethodback to summary
pack-priv static Object callMethod(Object obj, String name, Object... args) throws AttributeError, Throwable

Resolve a name within an object and then call it with the given positional arguments supplied from Java.

Parameters
obj:Object

target of the method invocation

name:String

identifying the method

args:Object[]

positional arguments

Returns:Object

result of call

Exceptions
AttributeError:
if the named callable cannot be found
Throwable:
from the called method
keywordTypeErrorback to summary
public static TypeError keywordTypeError(Object kwname)

Create a TypeError with a message along the lines "keywords must be strings, not 'X'" giving the type X of name.

Parameters
kwname:Object

actual object offered as a keyword

Returns:TypeError

exception to throw

namesArrayback to summary
pack-priv static String[] namesArray(PyTuple kwnames) throws TypeError

Convert a tuple of names to an array of Java String. This is useful when converting CPython-style keyword names in a call to the array of (guaranteed) String which most of the implementation of call expects.

Parameters
kwnames:PyTuple

(keyword) names to convert

Returns:String[]

the names as an array

Exceptions
TypeError:
if any keyword is not a string
stackAsDictback to summary
pack-priv static PyDict stackAsDict(Object[] stack, int start, int nargs, PyTuple kwnames)

Return a dictionary containing the last len(kwnames) elements of the slice stack[start:start+nargs]. This is a helper method to convert CPython vector calls (calls from a slice of an array, usually the stack) and involving keywords. kwnames normally contains only str objects, but that is not enforced here.

Parameters
stack:Object[]

positional and keyword arguments

start:int

position of arguments in the array

nargs:int

number of positional arguments

kwnames:PyTuple

tuple of names (may be null if empty)

Returns:PyDict

dictionary or null if kwnames==null

unpackDictback to summary
pack-priv static PyTuple unpackDict(Object[] args, Map<Object, Object> kwargs, Object[] stack) throws ArrayIndexOutOfBoundsException

Convert classic call arguments to an array and names of keywords to use in the CPython-style vector call.

Parameters
args:Object[]

positional arguments

kwargs:Map<Object, Object>

keyword arguments (normally PyDict)

stack:Object[]

to receive positional and keyword arguments, must be sized args.length + kwargs.size().

Returns:PyTuple

names of keyword arguments

vectorcallback to summary
pack-priv static Object vectorcall(Object callable, Object[] stack, int start, int nargs, PyTuple kwnames) throws Throwable

Call an object with the vector call protocol with some arguments given by keyword. This supports CPython byte code generated according to the conventions in PEP-590. Unlike its use in CPython, this is not likely to be faster than the standard call method.

Parameters
callable:Object

target

stack:Object[]

positional and keyword arguments

start:int

position of arguments in the array

nargs:int

number of positional and keyword arguments

kwnames:PyTuple

names of keyword arguments or null

Returns:Object

the return from the call to the object

Exceptions
Throwable:
for errors raised in the function
TypeError:
if target is not callable
See Also
FastCall#vectorcall(Object[], int, int, String[])
vectorcallback to summary
pack-priv static Object vectorcall(Object callable, Object[] stack, int start, int nargs) throws TypeError, Throwable

Call an object with the vector call protocol with no arguments given by keyword. This supports CPython byte code generated according to the conventions in PEP-590. Unlike its use in CPython, this is not likely to be faster than the standard call method.

Parameters
callable:Object

target

stack:Object[]

positional and keyword arguments (the stack)

start:int

position of arguments in the array

nargs:int

number of positional and keyword arguments

Returns:Object

the return from the call to the object

Exceptions
TypeError:
if target is not callable
Throwable:
for errors raised in the function
See Also
FastCall#vectorcall(Object[], int, int)