aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/attrs/attr/converters.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/python/attrs/attr/converters.py
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/attrs/attr/converters.py')
-rw-r--r--contrib/python/attrs/attr/converters.py54
1 files changed, 27 insertions, 27 deletions
diff --git a/contrib/python/attrs/attr/converters.py b/contrib/python/attrs/attr/converters.py
index dd1441ce4c..2777db6d0a 100644
--- a/contrib/python/attrs/attr/converters.py
+++ b/contrib/python/attrs/attr/converters.py
@@ -4,15 +4,15 @@ Commonly useful converters.
from __future__ import absolute_import, division, print_function
-from ._compat import PY2
+from ._compat import PY2
from ._make import NOTHING, Factory, pipe
-if not PY2:
- import inspect
- import typing
-
-
+if not PY2:
+ import inspect
+ import typing
+
+
__all__ = [
"pipe",
"optional",
@@ -25,9 +25,9 @@ def optional(converter):
A converter that allows an attribute to be optional. An optional attribute
is one which can be set to ``None``.
- Type annotations will be inferred from the wrapped converter's, if it
- has any.
-
+ Type annotations will be inferred from the wrapped converter's, if it
+ has any.
+
:param callable converter: the converter that is used for non-``None``
values.
@@ -39,23 +39,23 @@ def optional(converter):
return None
return converter(val)
- if not PY2:
- sig = None
- try:
- sig = inspect.signature(converter)
- except (ValueError, TypeError): # inspect failed
- pass
- if sig:
- params = list(sig.parameters.values())
- if params and params[0].annotation is not inspect.Parameter.empty:
- optional_converter.__annotations__["val"] = typing.Optional[
- params[0].annotation
- ]
- if sig.return_annotation is not inspect.Signature.empty:
- optional_converter.__annotations__["return"] = typing.Optional[
- sig.return_annotation
- ]
-
+ if not PY2:
+ sig = None
+ try:
+ sig = inspect.signature(converter)
+ except (ValueError, TypeError): # inspect failed
+ pass
+ if sig:
+ params = list(sig.parameters.values())
+ if params and params[0].annotation is not inspect.Parameter.empty:
+ optional_converter.__annotations__["val"] = typing.Optional[
+ params[0].annotation
+ ]
+ if sig.return_annotation is not inspect.Signature.empty:
+ optional_converter.__annotations__["return"] = typing.Optional[
+ sig.return_annotation
+ ]
+
return optional_converter
@@ -67,7 +67,7 @@ def default_if_none(default=NOTHING, factory=None):
:param default: Value to be used if ``None`` is passed. Passing an instance
of `attr.Factory` is supported, however the ``takes_self`` option
is *not*.
- :param callable factory: A callable that takes no parameters whose result
+ :param callable factory: A callable that takes no parameters whose result
is used if ``None`` is passed.
:raises TypeError: If **neither** *default* or *factory* is passed.