From 739694908f3d4cb8b594d2506ab6b96b19833b4e Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Fri, 3 Jul 2020 10:38:45 +0200 Subject: [PATCH] chore: Remove deprecated ``_accepts_context`` internal function --- docs/changelog.rst | 1 + src/schemathesis/_hypothesis.py | 14 +------------- src/schemathesis/hooks.py | 5 +---- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index e082a1f8cb..f205c7512a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -20,6 +20,7 @@ Removed ~~~~~~~ - Deprecated ``skip_validation`` argument to ``HookDispatcher.apply``. +- Deprecated ``_accepts_context`` internal function. `2.0.0`_ - 2020-07-01 --------------------- diff --git a/src/schemathesis/_hypothesis.py b/src/schemathesis/_hypothesis.py index 46668d45a8..32ad977922 100644 --- a/src/schemathesis/_hypothesis.py +++ b/src/schemathesis/_hypothesis.py @@ -1,6 +1,5 @@ """Provide strategies for given endpoint(s) definition.""" import asyncio -import inspect import re from base64 import b64encode from functools import partial @@ -16,7 +15,6 @@ from .exceptions import InvalidSchema from .hooks import GLOBAL_HOOK_DISPATCHER, HookContext, HookDispatcher from .models import Case, Endpoint -from .types import Hook PARAMETERS = frozenset(("path_parameters", "headers", "cookies", "query", "body", "form_data")) LOCATION_TO_CONTAINER = { @@ -201,17 +199,7 @@ def _apply_hooks(strategies: Dict[str, st.SearchStrategy], dispatcher: HookDispa for hook in dispatcher.get_all_by_name(f"before_generate_{key}"): # Get the strategy on each hook to pass the first hook output as an input to the next one strategy = strategies[key] - args: Union[Tuple[st.SearchStrategy], Tuple[HookContext, st.SearchStrategy]] - if _accepts_context(hook): - args = (context, strategy) - else: - args = (strategy,) - strategies[key] = hook(*args) - - -def _accepts_context(hook: Hook) -> bool: - # There are no restrictions on the first argument's name and we don't check its name here. - return len(inspect.signature(hook).parameters) == 2 + strategies[key] = hook(context, strategy) def register_string_format(name: str, strategy: st.SearchStrategy) -> None: diff --git a/src/schemathesis/hooks.py b/src/schemathesis/hooks.py index 514a23ba6d..5f95392da5 100644 --- a/src/schemathesis/hooks.py +++ b/src/schemathesis/hooks.py @@ -110,10 +110,7 @@ def add_dispatcher(cls, func: GenericTest) -> "HookDispatcher": return func._schemathesis_hooks # type: ignore def register_hook_with_name(self, hook: Callable, name: str) -> Callable: - """A helper for hooks registration. - - Besides its use in this class internally it is used to keep backward compatibility with the old hooks system. - """ + """A helper for hooks registration.""" self._validate_hook(name, hook) self._hooks[name].append(hook) return hook