Package io.deephaven.engine.util
Interface PythonScope<PyObj>
- Type Parameters:
PyObj
- the implementation's raw Python object type
- All Known Implementing Classes:
PythonScopeJpyImpl
public interface PythonScope<PyObj>
A collection of methods around retrieving objects from the given Python scope.
The scope is likely coming from some sort of Python dictionary. The scope might be local, global, or other.
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
containsKey
(String name) Finds out if a variable is in scopeconvertStringKey
(PyObj key) The helper method to turn a raw key into a string key.convertValue
(PyObj value) The helper method to turn a raw value into an implementation specific object.org.jpy.PyDictWrapper
Equivalent togetValueRaw(String)
.map(convertValue(Object)
)default <T> Optional<T>
getValueRaw
(String name) Retrieves a value from the given scope.default <T> Optional<T>
getValueUnchecked
(String name) Equivalent togetValue(String)
.map(x -> (T)x);org.jpy.PyDictWrapper
void
popScope()
Pop the last Python scope pushed bypushScope(PyObject pydict)
from the thread scope stackvoid
pushScope
(org.jpy.PyObject pydict) Push the provided Python scope into the thread scope stack for subsequent operations on Tables
-
Method Details
-
getValueRaw
Retrieves a value from the given scope.No conversion is done.
- Parameters:
name
- the name of the python variable- Returns:
- the value, or empty
-
convertStringKey
The helper method to turn a raw key into a string key.Note: this assumes that all the keys are strings, which is not always true. Indices can also be tuples. TODO: revise interface as appropriate if this becomes an issue.
- Parameters:
key
- the raw key- Returns:
- the string key
- Throws:
IllegalArgumentException
- if the key is not a string
-
convertValue
The helper method to turn a raw value into an implementation specific object.This method should NOT convert PyObj of None type to null - we need to preserve the None object so it works with other Optional return values.
- Parameters:
value
- the raw value- Returns:
- the converted object value
-
containsKey
Finds out if a variable is in scope- Parameters:
name
- the name of the python variable- Returns:
- true iff the scope contains the variable
-
getValue
Equivalent togetValueRaw(String)
.map(convertValue(Object)
)- Parameters:
name
- the name of the python variable- Returns:
- the converted object value, or empty
-
getValue
- Type Parameters:
T
- the return type- Parameters:
name
- the name of the python variableclazz
- the class to cast to- Returns:
- the converted casted value, or empty
-
getValueUnchecked
Equivalent togetValue(String)
.map(x -> (T)x);- Type Parameters:
T
- the return type- Parameters:
name
- the name of the python variable- Returns:
- the converted casted value, or empty
-
mainGlobals
org.jpy.PyDictWrapper mainGlobals()- Returns:
- the Python's __main__ module namespace
-
currentScope
org.jpy.PyDictWrapper currentScope()- Returns:
- the current scope or the main globals if no scope is set
-
pushScope
void pushScope(org.jpy.PyObject pydict) Push the provided Python scope into the thread scope stack for subsequent operations on Tables- Parameters:
pydict
- a Python dictionary representing the current scope under which the Python code in running, it is the combination of module globals and function locals
-
popScope
void popScope()Pop the last Python scope pushed bypushScope(PyObject pydict)
from the thread scope stack
-