Skip to content

Commit

Permalink
fix mypy warnings for disallow_untyped_decorators (#469)
Browse files Browse the repository at this point in the history
* make decorator overload
* add comments
* add change notes
  • Loading branch information
beliaev-maksim committed Jan 12, 2022
1 parent 2ac730d commit 0852c09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
------

* Dropped support of Python 2.7, 3.5, 3.6
* Fixed issue with type annotation for `responses.activate` decorator. See #468
* Removed internal `_is_string` and `_ensure_str` functions
* Removed internal `_quote` from `test_responses.py`
* Removed internal `_matches` attribute of `RequestsMock` object.
Expand Down
20 changes: 17 additions & 3 deletions responses/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ from typing import (
List,
Tuple,
Union,
Iterable
Iterable,
overload,
Type
)

from io import BufferedReader, BytesIO
from re import Pattern
from requests.adapters import HTTPResponse, PreparedRequest
Expand All @@ -23,7 +26,6 @@ from unittest import mock as std_mock
from urllib.parse import quote as quote
from urllib3.response import HTTPHeaderDict # type: ignore # Not currently exposed in typestubs.
from .matchers import urlencoded_params_matcher, json_params_matcher
from .registries import FirstMatchRegistry


def _clean_unicode(url: str) -> str: ...
Expand Down Expand Up @@ -275,7 +277,19 @@ class _Registered(Protocol):
def __call__(self) -> List[Response]: ...


activate: Any
class _Activate(Protocol):
# see https://github.com/getsentry/responses/pull/469 for more details

@overload
def __call__(self, func: _F = ...) -> _F: ...
# use this overload for scenario when 'responses.activate' is used

@overload
def __call__(self, registry: Type[Any] = ...) -> Callable[['_F'], '_F']: ...
# use this overload for scenario when 'responses.activate(registry=)' is used


activate: _Activate
add: _Add
add_callback: _AddCallback
add_passthru: _AddPassthru
Expand Down

0 comments on commit 0852c09

Please sign in to comment.