Skip to main content

Decorator to set a function's __annotations__ like Py3.

Project description

annotate

Function annotations.

Overview

@annotate

Decorator to set a function’s __annotations__ like Py3.

PyPI record.

Documentation.

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

Prerequisites:

To install run:

python -m pip install --upgrade annotate

Development

Prerequisites:

  • Development is strictly based on tox. To install it run:

    python -m pip install --upgrade tox

Visit development page.

Installation from sources:

clone the sources:

git clone https://github.com/karpierz/annotate.git annotate

and run:

python -m pip install ./annotate

or on development mode:

python -m pip install --editable ./annotate

License

Copyright (c) 2012-2022 Adam Karpierz
Licensed under the zlib/libpng License
Please refer to the accompanying LICENSE file.

Authors

Changelog

1.0.16 (2022-01-10)

  • Drop support for Python 2, 3.5 and 3.6.

  • Copyright year update.

  • Setup update.

1.0.15 (2020-10-18)

  • Setup: fix an improper dependencies versions.

  • Setup general update and cleanup.

  • Fixed docs setup.

1.0.8 (2019-05-21)

  • Update required setuptools version.

  • Setup update and improvements.

1.0.7 (2018-11-08)

  • Drop support for Python 2.6 and 3.0-3.3

  • Update required setuptools version.

1.0.6 (2018-05-08)

  • Update required setuptools version.

  • Improve and simplify setup and packaging.

1.0.5 (2018-02-26)

  • Improve and simplify setup and packaging.

1.0.4 (2018-01-28)

  • Fix a bug and inconsistencies in tox.ini

  • Update of README.rst.

1.0.1 (2018-01-24)

  • Update required Sphinx version.

  • Update doc Sphinx configuration files.

1.0.0 (2017-11-18)

  • Setup improvements.

  • Other minor improvements.

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.

Project details


Download files

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

Source Distribution

annotate-1.0.16.zip (19.9 kB view details)

Uploaded Source

Built Distribution

annotate-1.0.16-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file annotate-1.0.16.zip.

File metadata

  • Download URL: annotate-1.0.16.zip
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for annotate-1.0.16.zip
Algorithm Hash digest
SHA256 132ddd976008076ba1039b9a3b27112b1be1e37a6c89c800fb7079c61cb7b7c5
MD5 184c8c8c08cd3210dd0f89782d53e97f
BLAKE2b-256 3e353caeb1f1a5ddf847e3bc1438ebf42f6720cd4e80e8a37b0e55dbaef60bc5

See more details on using hashes here.

File details

Details for the file annotate-1.0.16-py3-none-any.whl.

File metadata

  • Download URL: annotate-1.0.16-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

File hashes

Hashes for annotate-1.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 d1beca6f6a5a01caa8ce98d2549a856f3f0c2243749a8ccbf9745373fa89aaa3
MD5 b699c6ebb3250cd98370613038174520
BLAKE2b-256 8bd5d83447e71d8c6febe440769901d46103250eb8844a807d3c91c342a6ac55

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page