Skip to main content

Library for convenient generation of annotations for your code

Project description

Pyannotating

Allows you to create similar annotations without copying them all the time.
It is advisable to place annotations created using this library in annotations.py file.

Installation

pip install pyannotating

Examples

Creating a factory of your annotations

from pyannotating import CustomAnnotationFactory, input_annotation
from typing import Callable

handler_of = CustomAnnotationFactory(Callable, [[input_annotation], any])

Now you can create an annotation by this factory

handler_of[int | float]

What is equivalent

Callable[[int | float], any]

Also you can use Union with input_annotation

summator_of = CustomAnnotationFactory(Callable, [[input_annotation | int, input_annotation], int])
summator_of[SomeCustomNumber]

What results in

Callable[[SomeCustomNumber | int, SomeCustomNumber], int]

Ultimately you can annotate by the results of factories

def some_operation_by(
    main: handler_of[int | float],
    *middleware: summator_of[SomeCustomNumber]
) -> handler_of[int | float]:
    ...

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

pyannotating-1.0.0.tar.gz (15.5 kB view hashes)

Uploaded Source

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