Top Description Fields Constructors Methods
org.python.core

pack-priv abstract Class Descriptor

extends AbstractPyObject
Class Inheritance
Known Direct Subclasses
org.python.core.MethodDescriptor, org.python.core.DataDescriptor
Imports
org.python.core.Slot.EmptyException

The base class of many built-in descriptors. Descriptors are a fundamental component of the Python type system, populating the dictionary of every type.

Implementation Note

It must be possible to create an instance of any concrete descriptor (a sub-class of this one) in circumstances where the only types in existence are PyType#TYPE and PyType#OBJECT_TYPE, and where these have not yet been given their descriptor attributes or operation slots (op_* slots}.

In order to create a descriptor, the JVM need only complete the static initialisation of the Java class for that descriptor and be able to execute the constructor.

Field Summary

Modifier and TypeField and Description
protected static final String
protected static final String
protected static final String
protected static final Slot.EmptyException
EMPTY

Single re-used instance of Slot.

protected final String
name

Name of the object described, e.g. "__add__" or "to_bytes".

protected final PyType
objclass

Python type that defines the attribute being described (e.g. for a method, the Python type of the object that will be "self" in a call).

protected String
qualname

Qualified name of the object described, e.g. "float.__add__" or "int.to_bytes".

Constructor Summary

AccessConstructor and Description
pack-priv
Descriptor(PyType descrtype, PyType objclass, String name)

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract Object

Returns:

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

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

private String
protected void
check(Object
target object (non-null argument to __get__)
obj
)

descr.__get__(obj, type) has been called on this descriptor.

pack-priv static Object
protected String

Returns:

repr as a str
descrRepr
(String
description of type (first word in the repr)
kind
)

Helper for __repr__ implementation.

public String
toString()

Overrides org.python.core.AbstractPyObject.toString.

Returns a string representation of the object.
Inherited from org.python.core.AbstractPyObject:
getType

Field Detail

DESCRIPTOR_DOESNT_APPLYback to summary
protected static final String DESCRIPTOR_DOESNT_APPLY
DESCRIPTOR_NEEDS_ARGUMENTback to summary
protected static final String DESCRIPTOR_NEEDS_ARGUMENT
DESCRIPTOR_REQUIRESback to summary
protected static final String DESCRIPTOR_REQUIRES
EMPTYback to summary
protected static final Slot.EmptyException EMPTY

Single re-used instance of Slot.EmptyException

nameback to summary
protected final String name

Name of the object described, e.g. "__add__" or "to_bytes". This is exposed to Python as __name__.

Annotations
@Member:__name__
readonly:true
objclassback to summary
protected final PyType objclass

Python type that defines the attribute being described (e.g. for a method, the Python type of the object that will be "self" in a call). This is exposed to Python as __objclass__.

qualnameback to summary
protected String qualname

Qualified name of the object described, e.g. "float.__add__" or "int.to_bytes". This is exposed to Python as __qualname__.

Constructor Detail

Descriptorback to summary
pack-priv Descriptor(PyType descrtype, PyType objclass, String name)

Method Detail

__get__back to summary
pack-priv abstract Object __get__(Object obj, PyType type) throws Throwable

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

API Note

Different descriptor types may have quite different behaviour. In general, a call made with obj == null is seeking a result related to the type, while in one where obj != null, obj must be of type objclass and type will be ignored.

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

Exceptions
Throwable:
from the implementation of the getter
calculate_qualnameback to summary
private String calculate_qualname() throws AttributeError, Throwable
checkback to summary
protected void check(Object obj) throws TypeError

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.

Parameters
obj:Object

target object (non-null argument to __get__)

Exceptions
TypeError:
if descriptor doesn't apply to obj
descr_get_qualnameback to summary
pack-priv static Object descr_get_qualname(Descriptor descr, Object ignored) throws AttributeError, Throwable
descrReprback to summary
protected String descrRepr(String kind)

Helper for __repr__ implementation. It formats together the kind argument ("member", "attribute", "method", or "slot wrapper"), this.name and this.objclass.name.

Parameters
kind:String

description of type (first word in the repr)

Returns:String

repr as a str

toStringback to summary
public String toString()

Overrides org.python.core.AbstractPyObject.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override