Skip to content

Commit 0f02d6e

Browse files
authored
Update README.md
1 parent 8dfc220 commit 0f02d6e

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ casting in python functions and classes.
1515

1616
## `pyoload.annotate`
1717

18-
Simple decorator over functions or classes
18+
Simple decorator over functions and classes
1919

2020
### functions
2121

@@ -43,15 +43,15 @@ a typechecker function which typechecks the passed value on each assignment.
4343
It also calls annotate on each of it's methods, except the class has a
4444
`__annotate_norecur__` attribute.
4545

46-
But if the attribute does not yes have annotations, it gets it using
47-
`type(val)` and adds it to the annotations.
46+
But if the assigned attribute does not yet have annotations, it gets them using
47+
`type(val)` and adds them to the annotations.
4848

4949
```python
5050
from pyoload import *
5151

5252
@annotate
5353
class Person:
54-
age: int
54+
age: 'int'
5555

5656
def __init__(self: Any, age: int, name: str):
5757
self.age = age
@@ -68,16 +68,16 @@ print(djamago.__annotations__)
6868
When decorating a function it:
6969
- annotates the function with the special kwarg `is_overload=True`
7070
- gets the function's name using `pyoload.get_name` and if needed
71-
creates a new register dictionarry value in
72-
`pyoload.__overloads__[name]` and stores a copy in
73-
the function's `.__pyod_overloads__`
71+
creates a new dictionarry value in
72+
`pyoload.__overloads__[name]` where it stores all overloads and stores a copy in
73+
the function's `.__pyod_overloads__` attribute.
7474

7575
And on each call it simply loops through each function entry, while
7676
it catches a `pyoload.InternalAnnotationError` which is raised when
7777
the special `is_overload` is set to true
7878

7979
> tip
80-
you may raise :python:`pyoload.InternalAnnotationError` inside an overloaded
80+
you may raise `pyoload.InternalAnnotationError` inside an overloaded
8181
function after carrying out some other checks and pyoload will switch to the
8282
next oveload.
8383

@@ -90,12 +90,12 @@ def foo(a: int):
9090
def foo(b: str, c: float):
9191
...
9292

93-
foo.overload
93+
@foo.overload
9494
def foo_hello(d: dict[str, list[int]]):
9595
...
9696
```
9797

98-
## tyme matches `pyoload.typeMatch(val, type)`
98+
## type checking with `pyoload.typeMatch(val, type)`
9999

100100
this function simply finds type compatibility between the passes arguments
101101

@@ -104,10 +104,11 @@ the type could be:
104104
- a Union e.g `int|str`
105105
- a generic alias e.g `dict[str, int]`
106106
- a subclass of `pyoload.PyoloadAnnotation` as:
107-
- `pyoload.Cast`
108107
- `pyoload.Checks`
109108
- `pyoload.Values`
110109

110+
111+
111112
## Casting with `pyoload.Cast`
112113

113114
Most pyoload decorators support `pyoload.Cast` instances,
@@ -162,6 +163,7 @@ def isnonecheck(param, value):
162163
if param != value:
163164
raise Check.CheckError(f'{param!r} not equal to {value!r}')
164165

166+
@annotate
165167
def foo(bar: Checks(is_equal=3)):
166168
pass
167169

@@ -181,10 +183,10 @@ It provides builtin checkes as: lt, gt, ge, le, eq, `func:Callable`,
181183

182184
## using `pyoload.CheckedAttr` and `pyoload.CastedAttr`
183185

184-
Felling not your to use such annotate or check?, `pyoload` provide
186+
`pyoload` provides:
185187
- `pyoload.CheckedAttr` A descriptor which does the type checking on
186188
assignment, and
187-
- `pyoload.CastedAttr` Which stores a casted copy of the values it is assigned
189+
- `pyoload.CastedAttr` Another descriptor Which stores a casted copy of the values it is assigned
188190

189191
```python
190192
class Person:

0 commit comments

Comments
 (0)