Skip to content

Reduce number of Optional return values#217

Merged
lundberg merged 12 commits intomasterfrom
fix/typing
Sep 16, 2022
Merged

Reduce number of Optional return values#217
lundberg merged 12 commits intomasterfrom
fix/typing

Conversation

@lundberg
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

codecov-commenter commented Sep 16, 2022

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6403618) to head (06ff405).
⚠️ Report is 41 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #217   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           20        20           
  Lines         2740      2796   +56     
  Branches       337       350   +13     
=========================================
+ Hits          2740      2796   +56     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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