mirror of
https://github.com/graphql-python/graphene.git
synced 2025-09-21 19:32:33 +03:00
File is deprecated and not used anywhere
This commit is contained in:
parent
07209755c2
commit
2d65a91aac
|
@ -1,35 +0,0 @@
|
||||||
import six
|
|
||||||
|
|
||||||
from ..pyutils.compat import func_name, signature
|
|
||||||
from .deprecated import warn_deprecation
|
|
||||||
|
|
||||||
|
|
||||||
def annotate(_func=None, _trigger_warning=True, **annotations):
|
|
||||||
if not six.PY2 and _trigger_warning:
|
|
||||||
warn_deprecation(
|
|
||||||
"annotate is intended for use in Python 2 only, as you can use type annotations Python 3.\n"
|
|
||||||
"Read more in https://docs.python.org/3/library/typing.html"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not _func:
|
|
||||||
|
|
||||||
def _func(f):
|
|
||||||
return annotate(f, **annotations)
|
|
||||||
|
|
||||||
return _func
|
|
||||||
|
|
||||||
func_signature = signature(_func)
|
|
||||||
|
|
||||||
# We make sure the annotations are valid
|
|
||||||
for key, value in annotations.items():
|
|
||||||
assert key in func_signature.parameters, (
|
|
||||||
'The key {key} is not a function parameter in the function "{func_name}".'
|
|
||||||
).format(key=key, func_name=func_name(_func))
|
|
||||||
|
|
||||||
func_annotations = getattr(_func, "__annotations__", None)
|
|
||||||
if func_annotations is None:
|
|
||||||
_func.__annotations__ = annotations
|
|
||||||
else:
|
|
||||||
_func.__annotations__.update(annotations)
|
|
||||||
|
|
||||||
return _func
|
|
|
@ -1,37 +0,0 @@
|
||||||
import pytest
|
|
||||||
|
|
||||||
from ..annotate import annotate
|
|
||||||
|
|
||||||
|
|
||||||
def func(a, b, *c, **d):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
annotations = {"a": int, "b": str, "c": list, "d": dict}
|
|
||||||
|
|
||||||
|
|
||||||
def func_with_annotations(a, b, *c, **d):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
func_with_annotations.__annotations__ = annotations
|
|
||||||
|
|
||||||
|
|
||||||
def test_annotate_with_no_params():
|
|
||||||
annotated_func = annotate(func, _trigger_warning=False)
|
|
||||||
assert annotated_func.__annotations__ == {}
|
|
||||||
|
|
||||||
|
|
||||||
def test_annotate_with_params():
|
|
||||||
annotated_func = annotate(_trigger_warning=False, **annotations)(func)
|
|
||||||
assert annotated_func.__annotations__ == annotations
|
|
||||||
|
|
||||||
|
|
||||||
def test_annotate_with_wront_params():
|
|
||||||
with pytest.raises(Exception) as exc_info:
|
|
||||||
annotate(p=int, _trigger_warning=False)(func)
|
|
||||||
|
|
||||||
assert (
|
|
||||||
str(exc_info.value)
|
|
||||||
== 'The key p is not a function parameter in the function "func".'
|
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user