Top Description Inners
org.python.core

public Interface Exposed

Static Imports
java.lang.annotation.ElementType.FIELD, .ElementType.METHOD, .ElementType.PARAMETER, .ElementType.TYPE, .RetentionPolicy.RUNTIME

Annotations that may be placed on elements of a Java class intended as the implementation of a Python type, and that the Exposer will look for when during the definition of a PyType.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
Exposed.Default

Provide default value for the annotated parameter.

public static @interface
Exposed.Deleter

Identify a method as that to be called during a Python call to __delattr__ naming an exposed attribute.

public static @interface
Exposed.DocString

Specify the documentation string (__doc__) for a method, field, etc. defined in Java and exposed to Python.

public static @interface
Exposed.FrozenArray

Documentation-only annotation reminding us that the defining class guarantees not to change the contents.

public static @interface
Exposed.Getter

Identify a method as that to be called during a Python call to __getattribute__ naming an exposed attribute.

public static @interface
Exposed.KeywordCollector

Declare that the annotated parameter is the collector for excess keyword arguments.

public static @interface
Exposed.KeywordOnly

Declare that the annotated parameter is the first keyword only parameter.

public static @interface
Exposed.Member

Identify a field of a Python object as an exposed attribute.

public static @interface
Exposed.Name

Override the name of an parameter to a method defined in Java, as it will appear to Python (in generated signatures and error messages).

public static @interface
Exposed.PositionalCollector

Declare that the annotated parameter is the collector for excess positional arguments.

public static @interface
Exposed.PositionalOnly

Declare that the annotated parameter is the last positional only parameter.

public static @interface
Exposed.PythonMethod

Identify a Python instance method of a type or module defined in Java and exposed to Python.

public static @interface
Exposed.PythonStaticMethod

Identify a Python static method of a type or module defined in Java and exposed to Python.

public static @interface
Exposed.Setter

Identify a method as that to be called during a Python call to __setattr__ naming an exposed attribute.

org.python.core back to summary

public @Interface Exposed.Default

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:PARAMETER

Provide default value for the annotated parameter. This is equivalent to following it with "=" in a Python signature. Allowed values are a small subset of the Python literals, presented as a String: "None", an integer, or a single-quoted string. For example
 PyList split(
     @Default("None") Object sep,
     @Default("-1") int maxsplit
 )

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()
org.python.core back to summary

public @Interface Exposed.Deleter

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:METHOD

Identify a method as that to be called during a Python call to __delattr__ naming an exposed attribute.

The signature must be ()V.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

name of the attribute
value
()

Exposed name of the attribute, if different from the Java method name.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()

Exposed name of the attribute, if different from the Java method name. This name will relate the Getter, Setter and Deleter in a single descriptor.

Returns:String

name of the attribute

org.python.core back to summary

public @Interface Exposed.DocString

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:METHOD, FIELD, TYPE

Specify the documentation string (__doc__) for a method, field, etc. defined in Java and exposed to Python.

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()
org.python.core back to summary

public @Interface Exposed.FrozenArray

extends Annotation
Annotations
@Documented
@Target:FIELD

Documentation-only annotation reminding us that the defining class guarantees not to change the contents. If a new value is assigned, it will be a new array. It is therefore safe to take a reference to this array and treat it as frozen (e.g. to expose it as a tuple). There is no enforcement of this contract at run time.

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString
org.python.core back to summary

public @Interface Exposed.Getter

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:METHOD

Identify a method as that to be called during a Python call to __getattribute__ naming an exposed attribute.

The signature must be ()T where T can be Object if the implementor has no reason to do otherwise. (One reason might be type safety when calling the same method from Java.) The annotated method is responsible for converting to T from however the attribute is represented internally to the type.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

name of the attribute
value
()

Exposed name of the attribute, if different from the Java method name.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()

Exposed name of the attribute, if different from the Java method name. This name will relate the Getter, Setter and Deleter in a single descriptor.

Returns:String

name of the attribute

org.python.core back to summary

public @Interface Exposed.KeywordCollector

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:PARAMETER

Declare that the annotated parameter is the collector for excess keyword arguments. This is equivalent to preceding the name with "**" in a Python signature. The type must be PyDict.

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString
org.python.core back to summary

public @Interface Exposed.KeywordOnly

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:PARAMETER

Declare that the annotated parameter is the first keyword only parameter. This is equivalent to preceding it with "*, " in a Python signature.

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString
org.python.core back to summary

public @Interface Exposed.Member

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:FIELD

Identify a field of a Python object as an exposed attribute. Get, set and delete operations are provided automatically on a descriptor that will be entered in the dictionary of the type being defined. If the field is Java final it will be read-only.

Some primitive types and String receive special support for conversion from Python objects. A field of type Object may easily be made a member and will then receive any Python object.

The annotated field may have any Java reference type. In that case, an attempt to assign a Python object of the wrong Java type will raise a TypeError. This makes it possible to declare an attribute of a specific Python type. For example one enforce tuple values by declaring the field as a PyTuple. The field would also accept Python sub-classes of the attribute type, since they must be sub-classes in Java too.

This approach creates a limitation where the corresponding Python type has multiple Java implementations not related by Java inheritance and is not specially provided for (like String). The set operation of the Member attribute will reject instances that have the intended Python type but non-matching Java type (with a confusing TypeError to boot). A writable attribute of that type should be implemented as Object or using explicit Getter, Setter and Deleter methods.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if access following delete will raise an error
optional
()

A member may be null from Java or deleted from Python (if not read-only).

public boolean

Returns:

true if read-only.
readonly
()

public String

Returns:

name of the attribute
value
()

Exposed name of the member if different from the field.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

optionalback to summary
public boolean optional()

A member may be null from Java or deleted from Python (if not read-only). In this condition:

  • for a member annotated with optional=true, attempts to get or delete the member will produce an AttributeError, until it is set again.
  • where optional=false (default), a get will return None and delete will have no effect.
Returns:boolean

true if access following delete will raise an error

readonlyback to summary
public boolean readonly()
Returns:boolean

true if read-only.

valueback to summary
public String value()

Exposed name of the member if different from the field.

Returns:String

name of the attribute

org.python.core back to summary

public @Interface Exposed.Name

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:PARAMETER

Override the name of an parameter to a method defined in Java, as it will appear to Python (in generated signatures and error messages). It is preferable to use a name in Java that conventional for Python, and is only necessary to annotate one when the conventional name is impossible (e.g. "new").

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()
org.python.core back to summary

public @Interface Exposed.PositionalCollector

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:PARAMETER

Declare that the annotated parameter is the collector for excess positional arguments. This is equivalent to preceding the name with "*" in a Python signature. The type must be PyTuple.

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString
org.python.core back to summary

public @Interface Exposed.PositionalOnly

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:PARAMETER

Declare that the annotated parameter is the last positional only parameter. This is equivalent to following it with ", /" in a Python signature.

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString
org.python.core back to summary

public @Interface Exposed.PythonMethod

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:METHOD

Identify a Python instance method of a type or module defined in Java and exposed to Python. The signature must be a supported type for which coercions can be found for its parameters.

When found in the classes that define a built-in type, this annotation results in a method definition, then a descriptor in the dictionary of the type. When found in the class that defines a built-in module, this annotation results in a method definition in the module specification, and a bound method in the dictionary of each module instance created from it.

Annotations may appear on the parameters of a method annotated with PythonMethod. These further describe the method, defining the parameters as positional-only parameters, or providing default values. A method may also be annotated with a documentation string (in the Python sense), by means of the @DocString annotation.

In types that accept multiple implementations, more than one method of the same name may be annotated PythonMethod. Only one may be the primary definition (see PythonMethod#primary(), and only in that one are the documentation string and parameter annotations effective. (It need not be the first definition.) These annotations on the primary definition define the signature that Python sees.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true (the default) if and only if this is the primary definition of the method
positionalOnly
()

The element positionalOnly=false is used to indicate that the arguments in a call to the annotated method may be provided by keyword.

public boolean

Returns:

true (the default) if and only if this is the primary definition of the method
primary
()

The element primary=false is used to indicate that the annotated method is not the primary definition.

public String

Returns:

name of the method
value
()

Exposed name of the method if different from the declaration.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

positionalOnlyback to summary
public boolean positionalOnly()

The element positionalOnly=false is used to indicate that the arguments in a call to the annotated method may be provided by keyword. This provides the call with the semantics of a method defined in Python, where

def g(a, b, c):
    print(a, b, c)
may be called as
>>> g(b=2, c=3, a=1)
1 2 3
>>> g(**dict(b=2, c=3, a=1))
1 2 3
It is as if we had annotated an imaginary parameter before the first declared parameter (or self) with @PositionalOnly.

The default positional=true is the more frequent case for built-in methods, although it is the opposite of the default for methods defined in Python where it would have to be expressed as def g(a, b, c, /).

Returns:boolean

true (the default) if and only if this is the primary definition of the method

primaryback to summary
public boolean primary()

The element primary=false is used to indicate that the annotated method is not the primary definition.

Returns:boolean

true (the default) if and only if this is the primary definition of the method

valueback to summary
public String value()

Exposed name of the method if different from the declaration.

Returns:String

name of the method

org.python.core back to summary

public @Interface Exposed.PythonStaticMethod

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:METHOD

Identify a Python static method of a type or module defined in Java and exposed to Python. The signature must be a supported type for which coercions can be found for its parameters.

When found in the classes that define a built-in type, this annotation results in a method definition, then a staticmethod object in the dictionary of the type. When found in the class that defines a built-in module, this annotation results in a method definition in the module specification, and an unbound method in the dictionary of each module instance created from it.

Annotations may appear on the parameters of a method annotated with PythonStaticMethod. These further describe the method, defining the parameters as positional-only parameters, or providing default values. A method may also be annotated with a documentation string (in the Python sense), by means of the @DocString annotation.

Only one method of the given name, in a given class class, may be annotated as a PythonStaticMethod.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true (the default) if and only if this is the primary definition of the method
positionalOnly
()

The element positionalOnly=false is used to indicate that the arguments in a call to the annotated method may be provided by keyword.

public String

Returns:

name of the function
value
()

Exposed name of the function if different from the declaration.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

positionalOnlyback to summary
public boolean positionalOnly()

The element positionalOnly=false is used to indicate that the arguments in a call to the annotated method may be provided by keyword. This provides the call with the semantics of a function defined in Python, where

def g(a, b, c):
    print(a, b, c)
may be called as
>>> g(b=2, c=3, a=1)
1 2 3
>>> g(**dict(b=2, c=3, a=1))
1 2 3
It is as if we had annotated an imaginary parameter before the first declared parameter (or self) with @PositionalOnly.

The default positional=true is the more frequent case for built-in function, although it is the opposite of the default for methods defined in Python where it would have to be expressed as def g(a, b, c, /).

Returns:boolean

true (the default) if and only if this is the primary definition of the method

valueback to summary
public String value()

Exposed name of the function if different from the declaration.

Returns:String

name of the function

org.python.core back to summary

public @Interface Exposed.Setter

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:METHOD

Identify a method as that to be called during a Python call to __setattr__ naming an exposed attribute.

The signature must be (T)V where T is often Object. The annotated method is responsible for converting this to the form in which the attribute is represented internally to the type. If Tis something more specific than Object, a cast occurs to this Java type during the descriptor call, which if it fails will raise a Python TypeError.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

name of the attribute
value
()

Exposed name of the attribute, if different from the Java method name.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()

Exposed name of the attribute, if different from the Java method name. This name will relate the Getter, Setter and Deleter in a single descriptor.

Returns:String

name of the attribute