diff --git a/README.md b/README.md index bb60e09a..338cf5a0 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ True - [Issue Tracker](http://github.com/kvesteri/validators/issues) - [Code](http://github.com/kvesteri/validators/) -[bs-badge]: https://github.com/kvesteri/validators/workflows/GH/badge.svg -[bs-link]: https://github.com/kvesteri/validators/actions/workflows/main.yml +[bs-badge]: https://github.com/python-validators/validators/actions/workflows/main.yml/badge.svg +[bs-link]: https://github.com/python-validators/validators/actions/workflows/main.yml [vs-badge]: https://img.shields.io/pypi/v/validators.svg [vs-link]: https://pypi.python.org/pypi/validators/ [dw-badge]: https://img.shields.io/pypi/dm/validators.svg diff --git a/README.rst b/README.rst index 192b45cd..17b7fe64 100644 --- a/README.rst +++ b/README.rst @@ -26,8 +26,8 @@ Resources - `Code `_ -.. |Build Status| image:: https://github.com/kvesteri/validators/workflows/GH/badge.svg - :target: https://github.com/kvesteri/validators/actions/workflows/main.yml +.. |Build Status| image:: https://github.com/python-validators/validators/actions/workflows/main.yml/badge.svg + :target: https://github.com/python-validators/validators/actions/workflows/main.yml .. |Version Status| image:: https://img.shields.io/pypi/v/validators.svg :target: https://pypi.python.org/pypi/validators/ .. |Downloads| image:: https://img.shields.io/pypi/dm/validators.svg diff --git a/poetry.lock b/poetry.lock index 50151020..71d12eec 100644 --- a/poetry.lock +++ b/poetry.lock @@ -151,6 +151,22 @@ mccabe = ">=0.7.0,<0.8.0" pycodestyle = ">=2.10.0,<2.11.0" pyflakes = ">=3.0.0,<3.1.0" +[[package]] +name = "flake8-docstrings" +version = "1.7.0" +description = "Extension for flake8 which uses pydocstyle to check docstrings" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "flake8_docstrings-1.7.0-py2.py3-none-any.whl", hash = "sha256:51f2344026da083fc084166a9353f5082b01f72901df422f74b4d953ae88ac75"}, + {file = "flake8_docstrings-1.7.0.tar.gz", hash = "sha256:4c8cc748dc16e6869728699e5d0d685da9a10b0ea718e090b1ba088e67a941af"}, +] + +[package.dependencies] +flake8 = ">=3" +pydocstyle = ">=2.1" + [[package]] name = "gitdb" version = "4.0.10" @@ -312,6 +328,24 @@ files = [ {file = "pycodestyle-2.10.0.tar.gz", hash = "sha256:347187bdb476329d98f695c213d7295a846d1152ff4fe9bacb8a9590b8ee7053"}, ] +[[package]] +name = "pydocstyle" +version = "6.3.0" +description = "Python docstring style checker" +category = "dev" +optional = false +python-versions = ">=3.6" +files = [ + {file = "pydocstyle-6.3.0-py3-none-any.whl", hash = "sha256:118762d452a49d6b05e194ef344a55822987a462831ade91ec5c06fd2169d019"}, + {file = "pydocstyle-6.3.0.tar.gz", hash = "sha256:7ce43f0c0ac87b07494eb9c0b462c0b73e6ff276807f204d6b53edc72b7e44e1"}, +] + +[package.dependencies] +snowballstemmer = ">=2.2.0" + +[package.extras] +toml = ["tomli (>=1.2.3)"] + [[package]] name = "pyflakes" version = "3.0.1" @@ -446,6 +480,18 @@ files = [ {file = "smmap-5.0.0.tar.gz", hash = "sha256:c840e62059cd3be204b0c9c9f74be2c09d5648eddd4580d9314c3ecde0b30936"}, ] +[[package]] +name = "snowballstemmer" +version = "2.2.0" +description = "This package provides 29 stemmers for 28 languages generated from Snowball algorithms." +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "snowballstemmer-2.2.0-py2.py3-none-any.whl", hash = "sha256:c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a"}, + {file = "snowballstemmer-2.2.0.tar.gz", hash = "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1"}, +] + [[package]] name = "stevedore" version = "4.1.1" @@ -488,4 +534,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "9826226038da764dc0358470620269a3b3972eb592127cf316211a60247b41e1" +content-hash = "392ef3e099ecf405cfa55703c0d0a6f476669ac4a91c27c51d779e27a7131f70" diff --git a/pyproject.toml b/pyproject.toml index 850ff51f..ab9dd26a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ python = "^3.9" bandit = "^1.7.4" black = "^23.1.0" flake8 = "^6.0.0" +flake8-docstrings = "^1.7.0" pyright = "^1.1.293" pytest = "^7.2.1" setuptools = "^67.2.0" diff --git a/setup.cfg b/setup.cfg index cd343408..972ca226 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,6 +3,7 @@ [flake8] max-line-length = 100 +docstring-convention = google # [isort] # known_first_party = sqlalchemy_utils,tests diff --git a/validators/utils.py b/validators/utils.py index 72fd8750..938e3934 100644 --- a/validators/utils.py +++ b/validators/utils.py @@ -1,7 +1,4 @@ -""" -Utils.py --------- -""" +"""Utils.""" # -*- coding: utf-8 -*- # standard @@ -11,37 +8,31 @@ class ValidationFailure(Exception): - """ - Exception class when validation failure occurs - """ + """Exception class when validation failure occurs.""" def __init__(self, function: Callable[..., Any], arg_dict: Dict[str, Any]): + """Initialize Validation Failure.""" self.func = function self.__dict__.update(arg_dict) def __repr__(self) -> str: + """Repr Validation Failure.""" return ( f"ValidationFailure(func={self.func.__name__}, " + f"args={({k: v for (k, v) in self.__dict__.items() if k != 'func'})})" ) def __str__(self) -> str: + """Str Validation Failure.""" return repr(self) def __bool__(self) -> Literal[False]: + """Bool Validation Failure.""" return False def _func_args_as_dict(func: Callable[..., Any], *args: Any, **kwargs: Any) -> Dict[str, Any]: - """ - Return given function's positional and key value arguments as an ordered - dictionary. - - :param func: function to decorate - :param args: positional function arguments - :param kwargs: key value function arguments - """ - + """Return function's positional and key value arguments as an ordered dictionary.""" # TODO: find more efficient way to do it return dict( list(zip(dict.fromkeys(chain(getfullargspec(func)[0], kwargs.keys())), args)) @@ -50,8 +41,7 @@ def _func_args_as_dict(func: Callable[..., Any], *args: Any, **kwargs: Any) -> D def validator(func: Callable[..., Any]) -> Callable[..., Union[Literal[True], ValidationFailure]]: - """ - A decorator that makes given function validator. + """A decorator that makes given function validator. Whenever the given function is called and returns ``False`` value this decorator returns :class:`ValidationFailure` object. @@ -63,14 +53,16 @@ def validator(func: Callable[..., Any]) -> Callable[..., Union[Literal[True], Va ... return not (value % 2) >>> even(4) - True + # Output: True >>> even(5) - ValidationFailure(func=even, args={'value': 5}) + # Output: ValidationFailure(func=even, args={'value': 5}) + + Args: + `func`: function which is to be decorated. - :param func: function to decorate - :param args: positional function arguments - :param kwargs: key value function arguments + Returns: + Wrapper function as a decorator. """ def wrapper(*args: Any, **kwargs: Any) -> Union[Literal[True], ValidationFailure]: @@ -79,5 +71,15 @@ def wrapper(*args: Any, **kwargs: Any) -> Union[Literal[True], ValidationFailure if func(*args, **kwargs) else ValidationFailure(func, _func_args_as_dict(func, *args, **kwargs)) ) + # try: + # return ( + # True + # if func(*args, **kwargs) + # else ValidationFailure(func, _func_args_as_dict(func, *args, **kwargs)) + # ) + # except (AssertionError, TypeError) as err: + # print(err) + # finally: + # return ValidationFailure(func, _func_args_as_dict(func, *args, **kwargs)) return wrapper