Class PyType

    • Field Detail

      • TYPE

        public static final PyType TYPE
    • Method Detail

      • ensureDoc

        public static void ensureDoc​(PyObject dict)
        Ensure dict contains a __doc__.
        Parameters:
        dict - a PyObject mapping
      • ensureModule

        public static void ensureModule​(PyObject dict)
        Ensure dict contains a __module__, retrieving it from the current frame if it doesn't exist.
        Parameters:
        dict - a PyObject mapping
      • getStatic

        public PyObject getStatic()
      • needsFinalizer

        public final boolean needsFinalizer()
        Offers public read-only access to the protected field needs_finalizer.
        Returns:
        a boolean indicating whether the type implements __del__
      • compatibleForAssignment

        public void compatibleForAssignment​(PyType other,
                                            java.lang.String attribute)
        Ensures that the physical layout between this type and other are compatible. Raises a TypeError if not.
      • delBases

        public void delBases()
      • setBases

        public void setBases​(PyObject newBasesTuple)
      • getFlags

        public PyLong getFlags()
      • type___subclasses__

        public final PyObject type___subclasses__()
      • type___subclasscheck__

        public final boolean type___subclasscheck__​(PyObject inst)
      • type___instancecheck__

        public final boolean type___instancecheck__​(PyObject inst)
      • getProxyType

        public java.lang.Class<?> getProxyType()
        Returns the Java Class that this type inherits from, or null if this type is Python-only.
      • isSubType

        public boolean isSubType​(PyType supertype)
      • lookup

        public PyObject lookup​(java.lang.String name)
        Attribute lookup for name through mro objects' dicts. Lookups are cached.
        Parameters:
        name - attribute name (must be interned)
        Returns:
        found object or null
      • lookup_where

        public PyObject lookup_where​(java.lang.String name,
                                     PyObject[] where)
        Attribute lookup for name through mro objects' dicts. Lookups are cached. Returns where in the mro the attribute was found at where[0].
        Parameters:
        name - attribute name (must be interned)
        where - Where in the mro the attribute was found is written to index 0
        Returns:
        found object or null
      • super_lookup

        public PyObject super_lookup​(PyType ref,
                                     java.lang.String name)
      • addBuilder

        public static void addBuilder​(java.lang.Class<?> forClass,
                                      org.python.expose.TypeBuilder builder)
      • fromClass

        public static PyType fromClass​(java.lang.Class<?> c)
      • fromClass

        public static PyType fromClass​(java.lang.Class<?> c,
                                       boolean hardRef)
      • __findattr_ex__

        public PyObject __findattr_ex__​(java.lang.String name)
        Description copied from class: PyObject
        Attribute lookup hook. If the attribute is not found, null may be returned or a Py.AttributeError can be thrown, whatever is more correct, efficient and/or convenient for the implementing class. Client code should use PyObject.__getattr__(String) or PyObject.__findattr__(String). Both methods have a clear policy for failed lookups.
        Overrides:
        __findattr_ex__ in class PyObject
        Returns:
        The looked up value. May return null if the attribute is not found
      • __setattr__

        public void __setattr__​(java.lang.String name,
                                PyObject value)
        Description copied from class: PyObject
        A variant of the __setattr__ method which accepts a String as the key. This String must be interned.
        Overrides:
        __setattr__ in class PyObject
        Parameters:
        name - the name whose value will be set - must be an interned string .
        value - the value to set this name to
        See Also:
        PyObject.__setattr__(PyString, PyObject)
      • addMethod

        public void addMethod​(PyBuiltinMethod meth)
        Adds the given method to this type's dict under its name in its descriptor. If there's an existing item in the dict, it's replaced.
      • removeMethod

        public void removeMethod​(PyBuiltinMethod meth)
        Removes the given method from this type's dict or raises a KeyError.
      • __delattr__

        public void __delattr__​(java.lang.String name)
        Description copied from class: PyObject
        A variant of the __delattr__ method which accepts a String as the key. This String must be interned. By default, this will call __delattr__(PyString name) with the appropriate args. The only reason to override this method is for performance.
        Overrides:
        __delattr__ in class PyObject
        Parameters:
        name - the name which will be removed - must be an interned string .
        See Also:
        PyObject.__delattr__(PyString)
      • __call__

        public PyObject __call__​(PyObject[] args,
                                 java.lang.String[] keywords)
        Description copied from class: PyObject
        The basic method to override when implementing a callable object. The first len(args)-len(keywords) members of args[] are plain arguments. The last len(keywords) arguments are the values of the keyword arguments.
        Overrides:
        __call__ in class PyObject
        Parameters:
        args - all arguments to the function (including keyword arguments).
        keywords - the keywords used for all keyword arguments.
      • fastGetName

        public java.lang.String fastGetName()
      • pyGetName

        public PyObject pyGetName()
      • getName

        public java.lang.String getName()
      • pySetName

        public void pySetName​(PyObject name)
      • setName

        public void setName​(java.lang.String name)
      • pyDelName

        public void pyDelName()
      • getDict

        public PyObject getDict()
        Description copied from class: PyObject
        xxx implements where meaningful
        Overrides:
        getDict in class PyObject
        Returns:
        internal object __dict__ or null
      • getDoc

        public PyObject getDoc()
        Equivalent of CPython's typeobject.c::type_get_doc; handles __doc__ descriptors.
      • __tojava__

        public java.lang.Object __tojava__​(java.lang.Class<?> c)
        Description copied from class: PyObject
        Equivalent to the Jython __tojava__ method. Tries to coerce this object to an instance of the requested Java class. Returns the special object Py.NoConversion if this PyObject can not be converted to the desired Java class.
        Overrides:
        __tojava__ in class PyObject
        Parameters:
        c - the Class to convert this PyObject to.
      • getModule

        public PyObject getModule()
      • delModule

        public void delModule()
      • getAbstractmethods

        public PyObject getAbstractmethods()
      • setAbstractmethods

        public void setAbstractmethods​(PyObject value)
      • getNumSlots

        public int getNumSlots()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class PyObject
      • noAttributeError

        public void noAttributeError​(java.lang.String name)
        Raises AttributeError on type objects. The message differs from PyObject#noAttributeError, to mimic CPython behaviour.
        Overrides:
        noAttributeError in class PyObject
      • refersDirectlyTo

        public boolean refersDirectlyTo​(PyObject ob)
                                 throws java.lang.UnsupportedOperationException
        Description copied from interface: Traverseproc
        Optional operation. Should only be implemented if it is more efficient than calling Traverseproc.traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.
        Specified by:
        refersDirectlyTo in interface Traverseproc
        Throws:
        java.lang.UnsupportedOperationException