Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-morel committed Jun 27, 2024
1 parent a6ca2d2 commit bbf506b
Show file tree
Hide file tree
Showing 7 changed files with 4,168 additions and 5,589 deletions.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def foo(
a: str, # this has an annotation
b=3, # this uses a default value
c: int = 0 # here both
) -> None: # The return type
) -> tuple[str, int]: # The return type
...
```

Expand Down Expand Up @@ -80,13 +80,27 @@ These are what pyoload adds to the standard annotations:

A simple `tuple` subclass, use them as annotation and it will validate only
included values.
```python
@annotate
def foo(bar: Values(range(5))):
...
```

### `pyoload.Cast`

This performs recursive casting of the passed arguments into the specified type
It supports `dict` generic aliases as `dict[str, int | str] ` and tries cast in
the specified order when the type is a Union.

```python
@annotate
def foo(bar: Cast(tuple[int | str])):
print(bar)

foo((3, "3")) # (3, 3)
foo((3j, " ")) # ('3j', ' ')
```

### `pyoload.Checks`

Permits You tou use custom checker methods, e.g
Expand All @@ -100,6 +114,8 @@ def foo(a: Checks(func=test):
...
```

If the check name is prepended with a `_`, it will be negated, and an exception
is raised if it fails.
You can register your own checks using `Check.register`, as

```python
Expand All @@ -114,6 +130,28 @@ def foo(a: Checks(mycheck='param')):
...
```

Checks can be used as annotations;
called using `pyoload.Checks` as `Checks(foo=bar)(val)`; or
Invoked directly using `pyoload.Checks` as:
`Check.check(name, param, arg)`

#### len

Receives as argument an integer value specified the expected length or
a slice in which the length should be found

#### gt, lt, eq

Compares grater than, less than and aqual to from the parameter
to the value.

#### func

Uses a function for validation, the function could return a boolean
or raise an error.
It could be passed directly as positional arguments to pyoload.Checks
as: `Checks(func1, func2, foo=bar, foo2=bar2)`

### Checked and casted attributes

`CheckedAttr` and `CastedAttr`, are simple descriptors which will perform
Expand Down
11 changes: 11 additions & 0 deletions docs/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ to when I write this doc now, about

These are the highlights

--------------------------------------------------
pyoload v2.0.1
--------------------------------------------------

1. Corrected bug when using Unions of Generic Aliases
2. Inspect.signature called only once, but called again if annotations are
modified.
3. Added checks negation by prepending with `_`
4. A list of functions checks could now be passed as positional arguments
to `pyoload.Checks`

--------------------------------------------------
pyoload v2.0.0
--------------------------------------------------
Expand Down
Loading

0 comments on commit bbf506b

Please sign in to comment.