Skip to content
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

Reduce number of Optional return values #217

Merged
merged 12 commits into from
Sep 16, 2022
Merged

Reduce number of Optional return values #217

merged 12 commits into from
Sep 16, 2022

Conversation

lundberg
Copy link
Owner

@lundberg lundberg commented Sep 15, 2022

  • Add python 3.11 to nox test ssession
  • Runs mypy on both tests and respx
  • Add Call.has_response helper
  • Changes Call.response to raise instead of being optional
  • Changes CallList.last to raise instead of being optional
  • Changes M(), and Route.pattern, to not be optional by introducing a Noop pattern
  • Correctly type hint side effects



class CallList(list, mock.NonCallableMock):
def __init__(self, *args, name="respx", **kwargs):
super().__init__(*args, **kwargs)
def __init__(self, *args: Sequence[Call], name: Any = "respx") -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps name: str | None to mimic NonCallableMock?

Suggested change
def __init__(self, *args: Sequence[Call], name: Any = "respx") -> None:
def __init__(self, *args: Sequence[Call], name: str | None = "respx") -> None:

Ref: https://github.com/python/typeshed/blob/c9346f32e10fc631e691745e2a8c24bc3216642f/stdlib/unittest/mock.pyi#L110

Copy link
Owner Author

@lundberg lundberg Sep 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, but it's not possible due to this "unfortunate" solution ... https://github.com/lundberg/respx/blob/master/respx/models.py#L115

I use the route instance as mock name to allow it to be dynamic/lazy.

To give some context, the name is only visible on assertion errors, e.g. when accessing NonCallableMock .assert_called_once etc, and passing the route as name is to render an up-to-date repr/str when that happens.

Not a pretty solution, neither an important one 😉.

@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2022

Codecov Report

Merging #217 (06ff405) into master (6403618) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #217   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines         2740      2796   +56     
  Branches       337       350   +13     
=========================================
+ Hits          2740      2796   +56     
Impacted Files Coverage Δ
tests/test_remote.py 100.00% <ø> (ø)
respx/models.py 100.00% <100.00%> (ø)
respx/patterns.py 100.00% <100.00%> (ø)
tests/test_api.py 100.00% <100.00%> (ø)
tests/test_mock.py 100.00% <100.00%> (ø)
tests/test_patterns.py 100.00% <100.00%> (ø)
tests/test_router.py 100.00% <100.00%> (ø)
tests/test_stats.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@lundberg lundberg merged commit 207cd16 into master Sep 16, 2022
@lundberg lundberg deleted the fix/typing branch September 16, 2022 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants