Top Description Fields Constructors Methods
org.python.core

public Class PyBaseObject

extends AbstractPyObject
Class Inheritance
Imports
java.lang.invoke.MethodHandle, java.util.Map, org.python.core.Slot.Signature

The Python object object: all Python objects by default inherit its Python method implementations. The canonical implementation of object is Object. This class provides its Python behaviours.

Although all Python objects are sub-classes in Python of object, their implementation classes will not generally be sub-classes in Java of this one. In particular, many built-in types are not.

The Java implementation class of a type defined in Python will be derived from the canonical implementation class of the "solid base" it inherits in Python. This may be object, in which case the implementation class will be a sub-class in Java of this class.

Implementation Note

All exposed methods, special methods and attribute get, set and delete methods defined here must be declared static in Java, with an explicit Object self argument. (__new__ is excepted from this rule as it is static anyway.) This is so that methods defined here on object operate correctly on receiving Python objects whatever their Java class. Methods and fields must be package visible so that PyType is able to form MethodHandles to them using its default lookup object.

Field Summary

Modifier and TypeField and Description
public static final PyType
TYPE

The type object of object objects.

Constructor Summary

AccessConstructor and Description
protected
PyBaseObject(PyType
actual Python sub-class being created
type
)

Constructor for Python sub-class specifying type.

public
PyBaseObject()

Constructor for object.

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
__delattr__(Object
the target of the delete
obj
,
String
of the attribute
name
)

Slot#op_delattr has signature Signature#DELATTR and provides attribute deletion on the object.

pack-priv static Object

Returns:

attribute value
__getattribute__
(Object
the target of the get
obj
,
String
of the attribute
name
)

Slot#op_getattribute has signature Signature#GETATTR and provides attribute read access on the object and its type.

pack-priv static Object

Returns:

string form
__repr__
(Object
target of the operation
self
)

Slot#op_repr has signature Signature#UNARY and sometimes reproduces the source-code representation of the object.

pack-priv static void
__setattr__(Object
the target of the set
obj
,
String
of the attribute
name
,
Object
to give the attribute
value
)

Slot#op_setattr has signature Signature#SETATTR and provides attribute write access on the object.

pack-priv static Object

Returns:

string form
__str__
(Object
target of the operation
self
)

Slot#op_str has signature Signature#UNARY and returns a human-readable presentation of the object.

Inherited from org.python.core.AbstractPyObject:
getTypetoString

Field Detail

TYPEback to summary
public static final PyType TYPE

The type object of object objects.

Constructor Detail

PyBaseObjectback to summary
protected PyBaseObject(PyType type)

Constructor for Python sub-class specifying type.

Parameters
type:PyType

actual Python sub-class being created

PyBaseObjectback to summary
public PyBaseObject()

Constructor for object.

Method Detail

__delattr__back to summary
pack-priv static void __delattr__(Object obj, String name) throws AttributeError, Throwable

Slot#op_delattr has signature Signature#DELATTR and provides attribute deletion on the object. The default instance __delattr__ slot implements dictionary look-up on the type and the instance. It is the starting point for activating the descriptor protocol. The following order of precedence applies when setting the value of an attribute:

  1. call a data descriptor from the dictionary of the type
  2. remove an entry from the instance dictionary of obj
If a matching entry on the type is a data descriptor (case 1) , but it throws AttributeError, this is definitive and the instance dictionary (if any) will not be updated.
Parameters
obj:Object

the target of the delete

name:String

of the attribute

Exceptions
AttributeError:
if no such attribute or it is read-only
Throwable:
on other errors, typically from the descriptor
__getattribute__back to summary
pack-priv static Object __getattribute__(Object obj, String name) throws AttributeError, Throwable

Slot#op_getattribute has signature Signature#GETATTR and provides attribute read access on the object and its type. The default instance __getattribute__ slot implements dictionary look-up on the type and the instance. It is the starting point for activating the descriptor protocol. The following order of precedence applies when looking for the value of an attribute:

  1. a data descriptor from the dictionary of the type
  2. a value in the instance dictionary of obj
  3. a non-data descriptor from dictionary of the type
  4. a value from the dictionary of the type
If a matching entry on the type is a data descriptor (case 1), but throws AttributeError, the instance dictionary (if any) will be consulted, and the subsequent cases (3 and 4) skipped. A non-data descriptor that throws an AttributeError (case 3) causes case 4 to be skipped.
Parameters
obj:Object

the target of the get

name:String

of the attribute

Returns:Object

attribute value

Exceptions
AttributeError:
if no such attribute
Throwable:
on other errors, typically from the descriptor
__repr__back to summary
pack-priv static Object __repr__(Object self)

Slot#op_repr has signature Signature#UNARY and sometimes reproduces the source-code representation of the object.

Parameters
self:Object

target of the operation

Returns:Object

string form

__setattr__back to summary
pack-priv static void __setattr__(Object obj, String name, Object value) throws AttributeError, Throwable

Slot#op_setattr has signature Signature#SETATTR and provides attribute write access on the object. The default instance __setattr__ slot implements dictionary look-up on the type and the instance. It is the starting point for activating the descriptor protocol. The following order of precedence applies when setting the value of an attribute:

  1. call a data descriptor from the dictionary of the type
  2. place a value in the instance dictionary of obj
If a matching entry on the type is a data descriptor (case 1) , but it throws AttributeError, this is definitive and the instance dictionary (if any) will not be updated.
Parameters
obj:Object

the target of the set

name:String

of the attribute

value:Object

to give the attribute

Exceptions
AttributeError:
if no such attribute or it is read-only
Throwable:
on other errors, typically from the descriptor
__str__back to summary
pack-priv static Object __str__(Object self)

Slot#op_str has signature Signature#UNARY and returns a human-readable presentation of the object. The default definition of the __str__ slot is to invoke the __repr__ slot.

Parameters
self:Object

target of the operation

Returns:Object

string form