Skip to content

Commit

Permalink
fix(pop): overloading + default arg
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre committed Sep 17, 2020
1 parent 7c66c98 commit af84aac
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions respx/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Callable, Optional, Pattern, Union
from typing import Any, Callable, Optional, Pattern, TypeVar, Union, overload

from .mocks import MockTransport
from .models import ContentDataTypes, HeaderTypes, RequestPattern

DefaultType = TypeVar("DefaultType", bound=Any)

mock = MockTransport(assert_all_called=False)

aliases = mock.aliases
Expand Down Expand Up @@ -30,9 +32,20 @@ def reset() -> None:
mock.reset()


def pop(alias: Optional[str] = None) -> RequestPattern:
@overload
def pop(alias: str) -> RequestPattern:
...


@overload
def pop(alias: str, default: DefaultType) -> Union[RequestPattern, DefaultType]:
...


def pop(alias, default=...):
global mock
mock.pop(alias=alias)
return mock.pop(alias=alias, default=default)


def add(
method: Union[str, Callable],
Expand Down

0 comments on commit af84aac

Please sign in to comment.