Skip to content

type tests.sentry.incidents.action_handlers.* #98112

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

Merged
merged 1 commit into from
Aug 21, 2025

Conversation

thetruecpaul
Copy link
Contributor

Found a pattern where this module just needed their run_test methods typed.

@thetruecpaul thetruecpaul requested review from a team as code owners August 21, 2025 18:56
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 21, 2025
@@ -69,8 +68,8 @@ def run_test(self, incident, method):
metric_value=metric_value,
)

data = orjson.loads(responses.calls[0].request.body)
return data
# data = orjson.loads(responses.calls[0].request.body)
Copy link
Member

Choose a reason for hiding this comment

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

Intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Intended to delete; this return value is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Thanks for the callout!)

@@ -10,10 +11,15 @@ class FireTest(TestCase, abc.ABC):
__test__ = Abstract(__module__, __qualname__)

@abc.abstractmethod
def run_test(self, incident: Incident, method: str, **kwargs):
def run_test(self, incident: Incident, method: str, **kwargs: object) -> Any:
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the usage would it be better to have this typed as -> None vs Any. Like Any doesn't give us much info to work with

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the thing is: there are nine definitions of run_test in this module. Seven of them return None, the test_discord.py instance returns the result of orjson.loads (which is typed as Any), and the one in test_slack.py returns tuple[Incident, str].

The run_test return is only used in __init__.py, where it's returned immediately from run_fire_test — whose return is only used in test_slack.py, which needs the tuple return.

I can look into whether there's something smarter we can do for inheritance, but the tricky thing here is that this function genuinely is returning very different things.

Copy link
Contributor

@Christinarlong Christinarlong Aug 21, 2025

Choose a reason for hiding this comment

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

so I'm wondering if we could just get rid of those return values. It doesn't look like test_slack or test_discord care about the data returned in their usages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's needed in test_slack.py:136 but I think I can raise the relevant logic there.

@thetruecpaul
Copy link
Contributor Author

Test Plan:

mypy passes
pytest tests/sentry/incidents/action_handlers/** 100% passing

@@ -46,7 +46,7 @@ def setUp(self) -> None:
self.handler = SentryAppActionHandler()

@responses.activate
def run_test(self, incident, method):
def run_test(self, incident: Incident, method: str) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Missing **kwargs in run_test Method

The run_test method in these test files is missing the **kwargs parameter required by its abstract base method. This signature mismatch could cause runtime errors if additional arguments, like chart_url, are passed.

Additional Locations (5)

Fix in Cursor Fix in Web

Copy link

codecov bot commented Aug 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                  Coverage Diff                  @@
##             hackweek/typing-25   #98112   +/-   ##
=====================================================
  Coverage                      ?   80.63%           
=====================================================
  Files                         ?     8598           
  Lines                         ?   379421           
  Branches                      ?    24710           
=====================================================
  Hits                          ?   305941           
  Misses                        ?    73102           
  Partials                      ?      378           

Copy link
Contributor

@Christinarlong Christinarlong left a comment

Choose a reason for hiding this comment

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

🙏

@thetruecpaul thetruecpaul merged commit 8d35bb4 into hackweek/typing-25 Aug 21, 2025
62 checks passed
@thetruecpaul thetruecpaul deleted the hackweek/cpaul/testactionahldneere branch August 21, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants