Top Description Inners Fields Constructors Methods
org.python.core

pack-priv abstract Class PyMemberDescr

extends DataDescriptor
Class Inheritance
Known Direct Subclasses
org.python.core.PyMemberDescr._int, org.python.core.PyMemberDescr._double, org.python.core.PyMemberDescr.Reference
Imports
java.lang.invoke.MethodHandles, .MethodHandles.Lookup, .VarHandle, java.lang.reflect.Field, java.util.EnumSet, org.python.base.InterpreterError

Descriptor for an attribute that has been defined (by a @Member annotations) to get and optionally set or delete the value, with default type conversions.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
PyMemberDescr._Object

An object attribute that may be deleted (represented by null in Java).

private static class
PyMemberDescr._String

A string attribute that may be deleted (represented by null in Java).

pack-priv static enum
PyMemberDescr.Flag

Acceptable values in the flags.

private abstract static class
PyMemberDescr.Reference

Behaviour for reference types.

Field Summary

Modifier and TypeField and Description
pack-priv String
doc

Documentation string for the member (or null).

protected final EnumSet<PyMemberDescr.Flag>
flags

Attributes controlling access and audit.

pack-priv VarHandle
handle

Reference to the field (offset) to access.

pack-priv static final PyType
TYPE

The type of Python object this class implements.

private static final String

Constructor Summary

AccessConstructor and Description
pack-priv
PyMemberDescr(PyType
Python type containing this member
objclass
,
String
by which the member is known to Python
name
,
VarHandle
to the Java member
handle
,
EnumSet<PyMemberDescr.Flag>
characteristics controlling access
flags
,
String
documentation string
doc
)

Construct a PyMemberDescr from a client-supplied handle.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
__delete__(Object
object on which the attribute is sought
obj
)

Implements abstract org.python.core.DataDescriptor.__delete__.

The __delete__ special method of the Python descriptor protocol, implementing del obj.name.
pack-priv Object
__get__(Object
object on which the attribute is sought or null
obj
,
PyType
is 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
pack-priv void
__set__(Object
object on which the attribute is sought
obj
,
Object
to assign (not null)
value
)

Implements abstract org.python.core.DataDescriptor.__set__.

The __set__ special method of the Python descriptor protocol, implementing obj.name = value.
protected void
check(Object
target object (non-null argument to __get__)
obj
)

Overrides org.python.core.Descriptor.check.

descr.__get__(obj, type) has been called on this descriptor.
protected void
checkDelete(Object
target object (argument to __delete__)
obj
)

Overrides org.python.core.DataDescriptor.checkDelete.

descr.__delete__(obj) has been called on this descriptor.
protected void
checkSet(Object
target object (argument to __set__)
obj
)

Overrides org.python.core.DataDescriptor.checkSet.

descr.__set__(obj, value) has been called on this descriptor.
protected void
delete(Object
object to access via handle (never null)
obj
)

A method to delete del o.name.

pack-priv static PyMemberDescr

Returns:

descriptor for access to the field
forField
(PyType
Python type that owns the descriptor
objclass
,
String
by which member known externally
name
,
Field
field to expose through this descriptor
field
,
MethodHandles.Lookup
authorisation to access fields
lookup
,
EnumSet<PyMemberDescr.Flag>
supplying additional characteristics
flags
,
String
documentation string (may be null)
doc
)

Create a PyMemberDescr with behaviour specific to the class of object being exposed.

protected abstract Object

Returns:

field value
get
(Object
object to access via handle (never null)
obj
)

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed).

pack-priv static Object
protected abstract void
set(Object
object to access via handle (never null)
obj
,
Object
value to assign: never null, may be None
v
)

A method to set o.name = v, with conversion to the internal field value if necessary.

private static VarHandle
Inherited from org.python.core.DataDescriptor:
attrMustBeattrMustBecannotDeleteAttrcannotReadAttrcannotWriteAttr

Field Detail

docback to summary
pack-priv String doc

Documentation string for the member (or null).

flagsback to summary
protected final EnumSet<PyMemberDescr.Flag> flags

Attributes controlling access and audit. (In CPython, the RESTRICTED forms cause a call to sys.audit and are here for compatibility with that eventual idea.) Note that OPTIONAL, although in the API, is represented as a sub-class attribute, to minimise work in checkSet(Object) and checkDelete(Object)

handleback to summary
pack-priv VarHandle handle

Reference to the field (offset) to access.

TYPEback to summary
pack-priv static final PyType TYPE

The type of Python object this class implements.

UNSUPPORTED_TYPEback to summary
private static final String UNSUPPORTED_TYPE

Constructor Detail

PyMemberDescrback to summary
pack-priv PyMemberDescr(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc)

Construct a PyMemberDescr from a client-supplied handle. This allows all JVM-supported access modes, but you have to make your own handle.

Parameters
objclass:PyType

Python type containing this member

name:String

by which the member is known to Python

handle:VarHandle

to the Java member

flags:EnumSet<PyMemberDescr.Flag>

characteristics controlling access

doc:String

documentation string

Method Detail

__delete__back to summary
pack-priv void __delete__(Object obj) throws TypeError, Throwable

Implements abstract org.python.core.DataDescriptor.__delete__.

Doc from org.python.core.DataDescriptor.__delete__.

The __delete__ special method of the Python descriptor protocol, implementing del obj.name. In general, obj must be of type objclass.

Parameters
obj:Object

object on which the attribute is sought

Annotations
@Override
Exceptions
Throwable:
from the implementation of the deleter
__get__back to summary
pack-priv 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. If obj != null call get on it to return a value. obj must be of type objclass. A call made with obj == null returns this descriptor.

Parameters
obj:Object

object on which the attribute is sought or null

type:PyType

is ignored

Returns:Object

attribute value, bound object or this attribute

Annotations
@Override
__repr__back to summary
private Object __repr__()
Annotations
@SuppressWarnings:unused
__set__back to summary
pack-priv void __set__(Object obj, Object value) throws TypeError, Throwable

Implements abstract org.python.core.DataDescriptor.__set__.

Doc from org.python.core.DataDescriptor.__set__.

The __set__ special method of the Python descriptor protocol, implementing obj.name = value. In general, obj must be of type objclass.

Parameters
obj:Object

object on which the attribute is sought

value:Object

to assign (not null)

Annotations
@Override
Exceptions
Throwable:
from the implementation of the setter
checkback to summary
protected void check(Object obj) throws TypeError

Overrides org.python.core.Descriptor.check.

Doc from org.python.core.Descriptor.check.

descr.__get__(obj, type) has been called on this descriptor. We must check that the descriptor applies to the type of object supplied as the obj argument. From Python, anything could be presented, but when we operate on it, we'll be assuming the particular objclass type.

Implementation Note

Compare CPython descr_check in descrobject.c. We differ in that: (1) We throw directly on failure. (2) The condition obj==null (when found on a type) is the caller's job. (3) We fold the sys.audit call into this check.

Parameters
obj:Object

target object (non-null argument to __get__)

Annotations
@Override
Exceptions
TypeError:
if descriptor doesn't apply to obj
checkDeleteback to summary
protected void checkDelete(Object obj) throws TypeError

Overrides org.python.core.DataDescriptor.checkDelete.

descr.__delete__(obj) has been called on this descriptor. We must check that the descriptor applies to the type of object supplied as the obj argument. From Python, anything could be presented, but when we operate on it, we'll be assuming the particular objclass type.

Parameters
obj:Object

Doc from org.python.core.DataDescriptor.checkDelete.

target object (argument to __delete__)

Annotations
@Override
checkSetback to summary
protected void checkSet(Object obj) throws TypeError

Overrides org.python.core.DataDescriptor.checkSet.

descr.__set__(obj, value) has been called on this descriptor. We must check that the descriptor applies to the type of object supplied as the obj argument. From Python, anything could be presented, but when we operate on it, we'll be assuming the particular objclass type.

Parameters
obj:Object

target object (argument to __set__)

Annotations
@Override
Exceptions
TypeError:
if descriptor doesn't apply to obj
deleteback to summary
protected void delete(Object obj) throws TypeError, AttributeError

A method to delete del o.name. This method is called from __delete__(Object), after checks, to implement the type-specific delete.

Implementation Note

The default implementation is correct for primitive types (i.e. the majority) in raising TypeError with the message that the attribute cannot be deleted.

Parameters
obj:Object

object to access via handle (never null)

Exceptions
TypeError:
when not a type that can be deleted
AttributeError:
when already deleted/undefined
forFieldback to summary
pack-priv static PyMemberDescr forField(PyType objclass, String name, Field field, MethodHandles.Lookup lookup, EnumSet<PyMemberDescr.Flag> flags, String doc) throws InterpreterError

Create a PyMemberDescr with behaviour specific to the class of object being exposed.

Parameters
objclass:PyType

Python type that owns the descriptor

name:String

by which member known externally

field:Field

field to expose through this descriptor

lookup:MethodHandles.Lookup

authorisation to access fields

flags:EnumSet<PyMemberDescr.Flag>

supplying additional characteristics

doc:String

documentation string (may be null)

Returns:PyMemberDescr

descriptor for access to the field

Exceptions
InterpreterError:
if the field type is not supported
getback to summary
protected abstract Object get(Object obj) throws AttributeError

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed). This method is called from __get__(Object, PyType), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

Returns:Object

field value

member_get_docback to summary
pack-priv static Object member_get_doc(PyMemberDescr descr)
setback to summary
protected abstract void set(Object obj, Object v) throws AttributeError, TypeError, Throwable

A method to set o.name = v, with conversion to the internal field value if necessary. This method is called from __set__(Object, Object), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

v:Object

value to assign: never null, may be None

Exceptions
TypeError:
if v cannot be converted
Throwable:
potentially from conversion
varHandleback to summary
private static VarHandle varHandle(Field f, MethodHandles.Lookup lookup)
org.python.core back to summary

private Class PyMemberDescr._double

extends PyMemberDescr
Class Inheritance

Field Summary

Inherited from org.python.core.PyMemberDescr:
docflagshandleTYPE

Constructor Summary

AccessConstructor and Description
pack-priv
_double(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc)

Method Summary

Modifier and TypeMethod and Description
protected Object
get(Object
object to access via handle (never null)
obj
)

Implements abstract org.python.core.PyMemberDescr.get.

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed).
protected void
set(Object
object to access via handle (never null)
obj
,
Object
value to assign: never null, may be None
value
)

Implements abstract org.python.core.PyMemberDescr.set.

A method to set o.name = v, with conversion to the internal field value if necessary.
Inherited from org.python.core.PyMemberDescr:
__delete____get____set__checkcheckDeletecheckSetdeleteforFieldmember_get_doc

Constructor Detail

_doubleback to summary
pack-priv _double(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc)

Method Detail

getback to summary
protected Object get(Object obj)

Implements abstract org.python.core.PyMemberDescr.get.

Doc from org.python.core.PyMemberDescr.get.

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed). This method is called from __get__(Object, PyType), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

Returns:Object

field value

Annotations
@Override
setback to summary
protected void set(Object obj, Object value) throws TypeError, Throwable

Implements abstract org.python.core.PyMemberDescr.set.

Doc from org.python.core.PyMemberDescr.set.

A method to set o.name = v, with conversion to the internal field value if necessary. This method is called from __set__(Object, Object), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

value:Object

value to assign: never null, may be None

Annotations
@Override
Exceptions
TypeError:
if v cannot be converted
Throwable:
potentially from conversion
org.python.core back to summary

private Class PyMemberDescr._int

extends PyMemberDescr
Class Inheritance

Field Summary

Inherited from org.python.core.PyMemberDescr:
docflagshandleTYPE

Constructor Summary

AccessConstructor and Description
pack-priv
_int(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc)

Method Summary

Modifier and TypeMethod and Description
protected Object
get(Object
object to access via handle (never null)
obj
)

Implements abstract org.python.core.PyMemberDescr.get.

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed).
protected void
set(Object
object to access via handle (never null)
obj
,
Object
value to assign: never null, may be None
value
)

Implements abstract org.python.core.PyMemberDescr.set.

A method to set o.name = v, with conversion to the internal field value if necessary.
Inherited from org.python.core.PyMemberDescr:
__delete____get____set__checkcheckDeletecheckSetdeleteforFieldmember_get_doc

Constructor Detail

_intback to summary
pack-priv _int(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc)

Method Detail

getback to summary
protected Object get(Object obj)

Implements abstract org.python.core.PyMemberDescr.get.

Doc from org.python.core.PyMemberDescr.get.

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed). This method is called from __get__(Object, PyType), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

Returns:Object

field value

Annotations
@Override
setback to summary
protected void set(Object obj, Object value) throws TypeError, Throwable

Implements abstract org.python.core.PyMemberDescr.set.

Doc from org.python.core.PyMemberDescr.set.

A method to set o.name = v, with conversion to the internal field value if necessary. This method is called from __set__(Object, Object), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

value:Object

value to assign: never null, may be None

Annotations
@Override
Exceptions
TypeError:
if v cannot be converted
Throwable:
potentially from conversion
org.python.core back to summary

private Class PyMemberDescr._Object

extends Reference
Class Inheritance

An object attribute that may be deleted (represented by null in Java).

Field Summary

Inherited from org.python.core.PyMemberDescr.Reference:
optional

Constructor Summary

AccessConstructor and Description
pack-priv
_Object(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc, boolean optional)

Method Summary

Modifier and TypeMethod and Description
protected Object
get(Object
object to access via handle (never null)
obj
)

Implements abstract org.python.core.PyMemberDescr.get.

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed).
protected void
set(Object
object to access via handle (never null)
obj
,
Object
value to assign: never null, may be None
value
)

Implements abstract org.python.core.PyMemberDescr.set.

A method to set o.name = v, with conversion to the internal field value if necessary.
Inherited from org.python.core.PyMemberDescr.Reference:
delete

Constructor Detail

_Objectback to summary
pack-priv _Object(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc, boolean optional)

Method Detail

getback to summary
protected Object get(Object obj)

Implements abstract org.python.core.PyMemberDescr.get.

Doc from org.python.core.PyMemberDescr.get.

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed). This method is called from __get__(Object, PyType), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

Returns:Object

field value

Annotations
@Override
setback to summary
protected void set(Object obj, Object value) throws TypeError, Throwable

Implements abstract org.python.core.PyMemberDescr.set.

Doc from org.python.core.PyMemberDescr.set.

A method to set o.name = v, with conversion to the internal field value if necessary. This method is called from __set__(Object, Object), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

value:Object

value to assign: never null, may be None

Annotations
@Override
Exceptions
TypeError:
if v cannot be converted
Throwable:
potentially from conversion
org.python.core back to summary

private Class PyMemberDescr._String

extends Reference
Class Inheritance

A string attribute that may be deleted (represented by null in Java).

Field Summary

Inherited from org.python.core.PyMemberDescr.Reference:
optional

Constructor Summary

AccessConstructor and Description
pack-priv
_String(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc, boolean optional)

Method Summary

Modifier and TypeMethod and Description
protected Object
get(Object
object to access via handle (never null)
obj
)

Implements abstract org.python.core.PyMemberDescr.get.

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed).
protected void
set(Object
object to access via handle (never null)
obj
,
Object
value to assign: never null, may be None
value
)

Implements abstract org.python.core.PyMemberDescr.set.

A method to set o.name = v, with conversion to the internal field value if necessary.
Inherited from org.python.core.PyMemberDescr.Reference:
delete

Constructor Detail

_Stringback to summary
pack-priv _String(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc, boolean optional)

Method Detail

getback to summary
protected Object get(Object obj)

Implements abstract org.python.core.PyMemberDescr.get.

Doc from org.python.core.PyMemberDescr.get.

A method to get o.name, with conversion from the internal field value if necessary (which will always succeed). This method is called from __get__(Object, PyType), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

Returns:Object

field value

Annotations
@Override
setback to summary
protected void set(Object obj, Object value) throws TypeError, Throwable

Implements abstract org.python.core.PyMemberDescr.set.

Doc from org.python.core.PyMemberDescr.set.

A method to set o.name = v, with conversion to the internal field value if necessary. This method is called from __set__(Object, Object), after checks, to implement the type-specific conversion.

Parameters
obj:Object

object to access via handle (never null)

value:Object

value to assign: never null, may be None

Annotations
@Override
Exceptions
TypeError:
if v cannot be converted
Throwable:
potentially from conversion
org.python.core back to summary

pack-priv final Enum PyMemberDescr.Flag

extends Enum<PyMemberDescr.Flag>
Class Inheritance

Acceptable values in the flags.

Field Summary

Modifier and TypeField and Description
public static final PyMemberDescr.Flag
public static final PyMemberDescr.Flag
public static final PyMemberDescr.Flag
public static final PyMemberDescr.Flag

Constructor Summary

AccessConstructor and Description
private
Flag()

Method Summary

Modifier and TypeMethod and Description
public static PyMemberDescr.Flag
public static PyMemberDescr.Flag[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

OPTIONALback to summary
public static final PyMemberDescr.Flag OPTIONAL
READ_RESTRICTEDback to summary
public static final PyMemberDescr.Flag READ_RESTRICTED
READONLYback to summary
public static final PyMemberDescr.Flag READONLY
WRITE_RESTRICTEDback to summary
public static final PyMemberDescr.Flag WRITE_RESTRICTED

Constructor Detail

Flagback to summary
private Flag()

Method Detail

valueOfback to summary
public static PyMemberDescr.Flag valueOf(String name)
valuesback to summary
public static PyMemberDescr.Flag[] values()
org.python.core back to summary

private abstract Class PyMemberDescr.Reference

extends PyMemberDescr
Class Inheritance
Known Direct Subclasses
org.python.core.PyMemberDescr._String, org.python.core.PyMemberDescr._Object

Behaviour for reference types.

Field Summary

Modifier and TypeField and Description
protected final boolean
optional

Controls what happens when the attribute implementation is null, If true, get(Object) will raise AttributeError.

Inherited from org.python.core.PyMemberDescr:
docflagshandleTYPE

Constructor Summary

AccessConstructor and Description
pack-priv
Reference(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc, boolean optional)

Method Summary

Modifier and TypeMethod and Description
protected void
delete(Object
object to access via handle (never null)
obj
)

Overrides org.python.core.PyMemberDescr.delete.

A method to delete del o.name.
Inherited from org.python.core.PyMemberDescr:
__delete____get____set__checkcheckDeletecheckSetforFieldgetmember_get_docset

Field Detail

optionalback to summary
protected final boolean optional

Controls what happens when the attribute implementation is null, If true, get(Object) will raise AttributeError. If false, get(Object) will return None. Delete sets the attribute implementation to null.

Constructor Detail

Referenceback to summary
pack-priv Reference(PyType objclass, String name, VarHandle handle, EnumSet<PyMemberDescr.Flag> flags, String doc, boolean optional)

Method Detail

deleteback to summary
protected void delete(Object obj)

Overrides org.python.core.PyMemberDescr.delete.

Doc from org.python.core.PyMemberDescr.delete.

A method to delete del o.name. This method is called from __delete__(Object), after checks, to implement the type-specific delete.

If optional and the attribute is null, reference types raise an AttributeError.

Parameters
obj:Object

object to access via handle (never null)

Annotations
@Override