getsentry / responses

A utility for mocking out the Python Requests library.
Apache License 2.0
4.08k stars 348 forks source link

move unbound_send outside of the function #648

Closed beliaev-maksim closed 1 year ago

beliaev-maksim commented 1 year ago

Moving unbound_on_send outside of the function will allow users to override the method if they will need to without a need to rewrite the entire start method

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (c25a1c8) 100.00% compared to head (fd371e5) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #648 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 9 9 Lines 2872 2874 +2 ========================================= + Hits 2872 2874 +2 ``` | [Impacted Files](https://app.codecov.io/gh/getsentry/responses/pull/648?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry) | Coverage Δ | | |---|---|---| | [responses/\_\_init\_\_.py](https://app.codecov.io/gh/getsentry/responses/pull/648?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=getsentry#diff-cmVzcG9uc2VzL19faW5pdF9fLnB5) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

markstory commented 1 year ago

Moving unbound_on_send outside of the function will allow users to override the method if they will need to without a need to rewrite the entire start method

Is there a use case for overwriting this method and behavior?

beliaev-maksim commented 1 year ago

@markstory while working on the bug for moto I spotted that we always use the same _real_send. However, there might be a use case where we will use unbound_on_send in a nested responses mock as a real adapter. then user can intercept real send from a mock (eg in moto) and override it with responses.unbound_on_send

a bit hard to explain. here is more info and examples: https://github.com/getmoto/moto/issues/6417

beliaev-maksim commented 1 year ago

but generally, it will not hard. Since this produces a cleaner way to handle methods within class and provides more granular control