-
Notifications
You must be signed in to change notification settings - Fork 71
Improve request matching type stubs #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For #171 Modifications to `MockerCore`: - Adds the missing `url` parameter to the `register_uri` and `request` methods. - Renames the `path` parameters of `delete`, `get`, `head`, `options`, `patch`, `post`, and `put` methods to `url` to match the name of the corresponding parameter in `requests_mock.adapter.Adapter.register_uri`. - Changes the types of various `method` and `url` parameters to support the `requests_mock.adapter.ANY` "wildcard" value.
requests_mock/mocker.pyi
Outdated
| self, | ||
| method: str, | ||
| method: Union[str, Any], | ||
| url: Union[str, Pattern[str], Any], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the point of union-ing with Any, does it give any hints over just using Any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, no. Well, some tooling may go "hey, you might want to use str, but you can use Any", but mypy I don't think will care.
requests_mock/mocker.pyi
Outdated
| def get( | ||
| self, | ||
| path: Union[str, Pattern[str]], | ||
| url: Union[str, Pattern[str], Any], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch.
|
I think the best move is to strongly type In AnyMatcher = typing.NewType('AnyMatcher', object)
ANY: AnyMatcher = ...and then in def get(
self,
url: Union[str, Pattern[str], AnyMatcher] |
|
I've pushed a new commit that includes @pcorpet's suggestion and adds some request matching parameters that were missing. There are also several response-related parameters missing (e.g. |
For #171 Improvements: - Introduces the `AnyMatcher` type for the `requests_mock.adapter.ANY` matcher. - Adds the `request_headers` and `complete_qs` request matching parameters to `MockerCore`'s registration methods (e.g. `register_uri`, `request`, get`, etc.). - Adds the `response_list` parameter to `MockerCore`'s registration methods so that it can be specified as a positional argument as in the [documentation](https://requests-mock.readthedocs.io/en/latest/response.html#response-lists)'s examples. - Ensures that `Adapter`'s `register_uri` method supports the same request matching parameters as `MockerCore`'s `register_uri`.
|
@jamielennox: Any chance you might review and release this change soon? Let me know if you've got further questions or concerns I can help with. |
|
Ah, sorry - i have been busy and haven't checked in until i got the notification. Seems good to me, only thing i'd like (might not be possible) is the equivalent of a I can release this as 1.9.3 as it's a minor, non-functional update. |
|
released as 1.9.3 - thanks for the help and sorry it took a little while |
Addresses #171
Improvements:
urlparameter to theregister_uriandrequestmethods.pathparameters ofdelete,get,head,options,patch,post, andputmethods tourlto match the name of the corresponding parameter inrequests_mock.adapter.Adapter.register_uri.methodandurlparameters to support therequests_mock.adapter.ANY"wildcard" value.AnyMatchertype for therequests_mock.adapter.ANYmatcher (thanks, @pcorpet!).request_headersandcomplete_qsrequest matching parameters toMockerCore's registration methods (e.g.register_uri,request, get`, etc.).response_listparameter toMockerCore's registration methods so that it can be specified as a positional argument as in the documentation's examples.Adapter'sregister_urimethod supports the same request matching parameters asMockerCore'sregister_uri.