Skip to content

Commit

Permalink
Merge branch 'simplified-validators'
Browse files Browse the repository at this point in the history
  • Loading branch information
piccolbo committed Sep 28, 2019
2 parents 80d8060 + e8f5f87 commit acfeeee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
19 changes: 5 additions & 14 deletions autosig/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
# -*- coding: utf-8 -*-
"""Top-level package for autosig."""
from .autosig import (
Signature,
autosig,
check,
param,
)
__all__ = [
"Signature",
"autosig",
"check",
"param",
]
from .autosig import Signature, autosig, param

__all__ = ["Signature", "autosig", "param"]
__author__ = """Antonio Piccolboni"""
__email__ = 'autosig@piccolboni.info'
__version__ = '0.8.2'
__email__ = "autosig@piccolboni.info"
__version__ = "0.8.2"
8 changes: 5 additions & 3 deletions autosig/autosig.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def param(
----------
default : Any
The default value for the parameter (defaults to no default, that is, mandatory).
validator : callable or list thereof
A validator for the actual parameter. If list, all element of the list are called. Return value is ignored, only exceptions raised count.
validator : callable or type
If a callable, it takes the actual parameter as an argument, raising an exception if invalid; return value is discarded. If a type, the actual parameter must be instance of that type.
converter : callable
The callable is executed with the parameter as an argument and its value assigned to the parameter itself. Useful for type conversions, but not only (e.g. limit range of parameter).
The callable is executed with the parameter as an argument and its value assigned to the parameter itself. Useful for type conversions, but not only (e.g. truncate range of parameter).
docstring : string
Description of parameter `docstring` (the default is "").
position : int
Expand All @@ -46,6 +46,8 @@ def param(
Object describing all the properties of the parameter. Can be reused in multiple signature definitions to enforce consistency.
"""
if validator is not None:
validator = check(validator)
metadata = {AUTOSIG_DOCSTRING: docstring, AUTOSIG_POSITION: position}
kwargs = locals()
for key in ("docstring", "position"):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for autosig."""
from attr import asdict
from autosig import Signature, autosig, param, check
from autosig import Signature, autosig, param
from autosig.autosig import make_sig_class
from functools import partial
from hypothesis import (
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_argumentless_decorator():
"Non-randomized test for argumentless decorator"

@autosig
def fun(a=param(validator=check(int))):
def fun(a=param(validator=int)):
pass

fun(1)
Expand Down

0 comments on commit acfeeee

Please sign in to comment.