Skip to main content

Library of annotations for humans

Project description

Pyannotating

Structures your annotations and puts more information into them.

Installation

pip install pyannotating

Examples

Create annotation templates

from typing import Callable, Any, Optional, Iterable

from pyannotating import *


handler_of = AnnotationTemplate(Callable, [[input_annotation], Any])
handler_of[int | float]
Callable[[int | float], Any]

in a nested way

optional_reformer_of = AnnotationTemplate(
    Callable,
    [[input_annotation], AnnotationTemplate(Optional, [input_annotation])]
)

optional_reformer_of[int]
Callable[[int], Optional[int]]

with non-strict input annotation

summator_of = AnnotationTemplate(Callable, [[input_annotation | int, input_annotation], int])
summator_of[float]
Callable[[float | int, float], int]

Integrate comments into annotations

even = FormalAnnotation("Formal annotation of even numbers.")

number: even[int | float] = 42

or subgroups of existing types

natural_numbers = Subgroup(int, lambda number: number > 0)

isinstance(14, natural_numbers)
isinstance(-1.2, natural_numbers)

64 in natural_numbers
True
False
True

or downcasts

def transform(numbers: Special[range, Iterable[int]], additional: Special[None] = None) -> Any:
    ...

# Equals to

def transform(numbers: Iterable[int], additional: Any = None) -> Any:
    ...

or just some pre-made templates and annotations

many_or_one[int | float]
number
int | float | Iterable[int | float]
int | float | complex

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.3.0.tar.gz (16.6 kB view details)

Uploaded Source

File details

Details for the file pyannotating-1.3.0.tar.gz.

File metadata

  • Download URL: pyannotating-1.3.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for pyannotating-1.3.0.tar.gz
Algorithm Hash digest
SHA256 5530a9d585367a2eea58048c90936e1a7aa8cf61f0e38cd8af0715656c54c2bf
MD5 b5fd34dbd8c791a71763735b9d262e55
BLAKE2b-256 17971625d4b0e1a93d7242c0d386e41c9322b768254c8e2811bbcd7360b1dd5b

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