Skip to main content

annotate

Python Annotation System

About

Annotations are tags that store object metadata (e.g. for functions/classes)

Installation

From PyPI

pip install tombulled-annotate

From GitHub

pip install git+https://github.com/tombulled/annotate@main

Usage

Marker

An annotation with a fixed value

import annotate

@annotate.marker
def deprecated() -> bool:
    return True

@deprecated
def foo():
    pass
>>> annotate.get_annotations(foo)
{'deprecated': True}

Annotation

An annotation with a configurable value

import annotate

@annotate.annotation
def metadata(*, author: str, version: str) -> dict:
    return dict(
        author = author,
        version = version,
    )

@metadata(author='sam', version='1.0.1')
def foo():
    pass
>>> annotate.get_annotations(foo)
{'metadata': {'author': 'sam', 'version': '1.0.1'}}

Repeatable Annotation

An annotation that can be used to annotate the same object multiple times

import annotate

@annotate.annotation(repeatable=True)
def tag(tag: str, /) -> str:
    return tag

@tag('awesome')
@tag('cool')
@tag('funky')
def foo():
    pass
>>> annotate.get_annotations(foo)
{'tag': ['funky', 'cool', 'awesome']}

Inherited Annotation

An annotation that gets added to subclasses of an annotated class

import annotate

@annotate.annotation(inherited=True)
def identifier(identifier: str, /) -> str:
    return identifier

@identifier('abc')
class Class:
    pass

class Subclass(Class):
    pass
>>> annotate.get_annotations(Class)
{'identifier': 'abc'}
>>> annotate.get_annotations(Subclass)
{'identifier': 'abc'}

Targetted Annotation

An annotation that targets objects of specific types

import annotate
import types

@annotate.annotation(targets=(types.FunctionType,))
def description(description: str, /) -> str:
    return description

@description('A really cool function')
def foo():
    pass
>>> annotate.get_annotations(foo)
{'description': 'A really cool function'}

Non-Stored Annotation

import annotate

@annotate.annotation(stored=False)
def author(name: str, /) -> None:
    pass

@author('Tim')
def foo():
    pass
>>> annotate.get_annotations(foo)
{}

Metadata

Release files for tombulled-annotate 0.1.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tombulled-annotate 0.1.15
File Size Uploaded
tombulled_annotate-0.1.15.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tombulled-annotate 0.1.15
File Interpreter ABI Platform
tombulled_annotate-0.1.15-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / tombulled_annotate-0.1.15.tar.gz

Download URL tombulled_annotate-0.1.15.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d4ceb8ea87fbac60673fef4c1a06fa4e60585fa561f0795406c541e219afe85d
BLAKE2b-256 checksum
How to use checksums
da66b730f49b8fcd10e06a25fca36d80fc97ce4704ba0218619690655e082241
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.10 Linux/5.4.0-144-generic

Release files / tombulled_annotate-0.1.15-py3-none-any.whl

Download URL tombulled_annotate-0.1.15-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd51ad93d2326f632c0f35fcef7e449f9249c877b5128f0e2a8c227037c46a2c
BLAKE2b-256 checksum
How to use checksums
541d7307128face90b30861e9911baa8665cdc13c94549f782057bd7d95bc1d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.10 Linux/5.4.0-144-generic

Release history Release notifications | RSS feed

This release

0.1.15 This release

2 release files

0.1.14

2 release files

0.1.11

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page