Skip to content

Commit 17fd039

Browse files
committed
Up-to-date information for Readme
1 parent 0457161 commit 17fd039

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

README.md

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,75 @@
11
## Pyannotating
2-
Allows you to create similar annotations without copying them all the time.<br>
3-
It is advisable to place annotations created using this library in annotations.py file.
2+
Allows you to structure your annotations and put more information into them.<br>
3+
Templates created with this library should preferably be placed in the annotations.py file.
44

55
### Installation
66
`pip install pyannotating`
77

8-
### Examples
9-
Creating a factory of your annotations
8+
### Features
9+
You can create a template of your annotations
1010
```python
11-
from pyannotating import CustomAnnotationFactory, input_annotation
12-
from typing import Callable
11+
from pyannotating import *
12+
from typing import Callable, Any, Optional, Iterable
1313

14-
handler_of = CustomAnnotationFactory(Callable, [[input_annotation], any])
14+
handler_of = AnnotationTemplate(Callable, [[input_annotation], Any])
1515
```
16-
Now you can create an annotation by this factory
16+
and then create an annotation by this template
1717
```python
1818
handler_of[int | float]
1919
```
2020

21-
What is equivalent
21+
what is equivalent
2222
```python
23-
Callable[[int | float], any]
23+
Callable[[int | float], Any]
2424
```
2525

26-
Also you can use Union with input_annotation
26+
Also you can nest templates inside each other
2727
```python
28-
summator_of = CustomAnnotationFactory(Callable, [[input_annotation | int, input_annotation], int])
29-
summator_of[SomeCustomNumber]
28+
optional_handler_of = AnnotationTemplate(
29+
Callable,
30+
[[input_annotation], AnnotationTemplate(Optional, [input_annotation])]
31+
)
32+
33+
optional_handler_of[int]
34+
```
35+
36+
what results in
37+
```python
38+
Callable[[int], Optional[int]]
39+
```
40+
41+
and use input_annotation in conjunction with something else
42+
```python
43+
summator_of = AnnotationTemplate(Callable, [[input_annotation | int, input_annotation], int])
44+
summator_of[float]
3045
```
3146

32-
What results in
47+
to get
3348
```python
34-
Callable[[SomeCustomNumber | int, SomeCustomNumber], int]
49+
Callable[[float | int, float], int]
3550
```
3651

37-
In addition, you can also annotate something regardless of its type
52+
In addition, you can integrate comments with your annotations
3853
```python
3954
even = FormalAnnotation("Formal annotation of even numbers.")
4055

4156
number: even[int | float] = 42
4257
```
4358

44-
Full example
59+
or annotate downcasts
4560
```python
46-
def some_operation_by(
47-
handler: handler_of[int | float],
48-
number: even[float],
49-
*middleware_handlers: summator_of[SomeCustomNumber]
50-
) -> handler_of[int | float]:
61+
def transform(collection: Special[range, Iterable]) -> Any:
5162
...
5263
```
64+
65+
or just use some pre-made templates
66+
```python
67+
many_or_one[Callable]
68+
method_of[int]
69+
```
70+
71+
for getting
72+
```python
73+
Callable | Iterable[Callable]
74+
Callable[[int, ...], Any]
75+
```

0 commit comments

Comments
 (0)