Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Decorator to set a function's __annotations__ like Py3

Project Description

annotate

Function annotations for Python2.

Features

@annotate

Decorator to set a function’s __annotations__ like Py3.

Overview

TODO…

Examples

from typing   import Optional, Tuple, Union, Sequence
from annotate import annotate

from .lib import cached
from .    import jni

from .jobjectbase import JObjectBase
from .jclass      import JClass
from .jobject     import JObject


class JArray(JObjectBase):

    """Java Array"""

    @classmethod
    @annotate('JArray', size=Union[int, long])
    def newBooleanArray(cls, size):
        ...
    ...
    @classmethod
    @annotate('JArray', size=Union[int, long])
    def newDoubleArray(cls, size):
        ...
    @classmethod
    @annotate('JArray', size=Union[int, long])
    def newStringArray(cls, size):
        ...
    @classmethod
    @annotate('JArray', size=Union[int, long], component_class=JClass)
    def newObjectArray(cls, size, component_class):
        ...

    @annotate(jenv=jni.JNIEnv, jarr=jni.jarray, borrowed=bool)
    def __init__(self, jenv, jarr, borrowed=False):
        ...

    def __hash__(self):
        return super(JArray, self).__hash__()

    def __len__(self):
        return self.getLength()

    @annotate(JObject, borrowed=bool)
    def asObject(self, borrowed=False):
        ...

    @cached
    @annotate(int)
    def getLength(self):
        ...

    @annotate(bool, idx=int)
    def getBoolean(self, idx):
        ...
    ...
    @annotate(float, idx=int)
    def getDouble(self, idx):
        ...
    @annotate(Optional[str], idx=int)
    def getString(self, idx):
        ...
    @annotate(Optional[JObject], idx=int)
    def getObject(self, idx):
        ...

    @annotate(idx=int, val=bool)
    def setBoolean(self, idx, val):
        ...
    @annotate(idx=int, val=str)
    def setChar(self, idx, val):
        ...
    ...
    @annotate(idx=int, val=Union[int, long])
    def setLong(self, idx, val):
        ...
    @annotate(idx=int, val=float)
    def setDouble(self, idx, val):
        ...
    @annotate(idx=int, val=Optional[str])
    def setString(self, idx, val):
        ...
    @annotate(idx=int, val=Optional[JObject])
    def setObject(self, idx, val):
        ...

    @annotate('JArray', start=int, stop=int, step=int)
    def getBooleanSlice(self, start, stop, step):
        ...
    ...
    @annotate('JArray', start=int, stop=int, step=int)
    def getDoubleSlice(self, start, stop, step):
        ...
    @annotate('JArray', start=int, stop=int, step=int)
    def getStringSlice(self, start, stop, step):
        ...
    @annotate('JArray', start=int, stop=int, step=int)
    def getObjectSlice(self, start, stop, step):
        ...

    @annotate(start=int, stop=int, step=int, val=Sequence[bool])
    def setBooleanSlice(self, start, stop, step, val):
        ...
    @annotate(start=int, stop=int, step=int, val=Union[Sequence[str], str])
    def setCharSlice(self, start, stop, step, val):
        ...
    @annotate(start=int, stop=int, step=int,
              val=Union[Sequence[Union[int,bytes]], (bytes, bytearray)])
    def setByteSlice(self, start, stop, step, val):
        ...
    ...
    @annotate(start=int, stop=int, step=int, val=Sequence[float])
    def setDoubleSlice(self, start, stop, step, val):
        ...
    @annotate(start=int, stop=int, step=int, val=Sequence[Optional[str]])
    def setStringSlice(self, start, stop, step, val):
        ...
    @annotate(start=int, stop=int, step=int, val=Sequence[Optional[JObject]])
    def setObjectSlice(self, start, stop, step, val):
        ...

    @annotate(Tuple)
    def getBooleanBuffer(self):
        with self.jvm as (jvm, jenv):
            is_copy = jni.jboolean()
            return jenv.GetBooleanArrayElements(self._jobj, is_copy), jni.sizeof(jni.jboolean), b"B", is_copy
    ...
    @annotate(Tuple)
    def getDoubleBuffer(self):
        with self.jvm as (jvm, jenv):
            is_copy = jni.jboolean()
            return jenv.GetDoubleArrayElements(self._jobj, is_copy), jni.sizeof(jni.jdouble), b"d", is_copy

    @annotate(buf=object)
    def releaseBooleanBuffer(self, buf):
        with self.jvm as (jvm, jenv):
            jenv.ReleaseBooleanArrayElements(self._jobj, jni.cast(buf, jni.POINTER(jni.jboolean)))
    ...
    @annotate(buf=object)
    def releaseDoubleBuffer(self, buf):
        with self.jvm as (jvm, jenv):
            jenv.ReleaseDoubleArrayElements(self._jobj, jni.cast(buf, jni.POINTER(jni.jdouble)))

Installation

$ pip install --upgrade annotate

Prerequisites:

License

zlib/libpng License
Please refer to the bundled LICENSE file.

Authors

Changelog

0.7.4 (2017-01-05)

  • Minor setup improvements.

0.7.3 (2016-09-25)

  • Fix bug in setup.py

0.7.1 (2016-09-25)

  • More PEP8 compliant

0.6.7 (2016-09-24)

  • Minor description suplement

0.6.4 (2016-09-23)

  • Simplify package structure.

0.6.3 (2016-06-19)

  • Fix incompatibility for older versions of setuptools.
    Add example.

0.6.0 (2015-08-17)

  • Python3 support.

0.5.1 (2015-02-27)

  • Remove ‘returns’ as keyword argument for declare return type.
    For now, the type of returned value should be declared by the first
    positional argument.

0.3.3 (2014-09-15)

  • Add wheels.

0.3.2 (2014-09-13)

  • Standarize package.

0.3.0 (2014-09-06)

  • Standarize package.
  • Cosmetic changes.

0.2.6 (2014-06-10)

  • Portable setup.py.

0.2.5 (2014-06-10)

  • Cosmetic changes.

0.2.3 (2012-10-13)

  • Initial release.
Release History

Release History

This version
History Node

0.7.4

History Node

0.7.3

History Node

0.6.7

History Node

0.6.4

History Node

0.6.3

History Node

0.6.2

History Node

0.6.1

History Node

0.6.0

History Node

0.5.1

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.7

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
annotate-0.7.4.zip (10.4 kB) Copy SHA256 Checksum SHA256 Source Jan 6, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting