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

chore(slack): correctly type issue message builder #74876

Merged
merged 10 commits into from
Jul 29, 2024

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Jul 24, 2024

Fixing typing for the issues Slack message builder.

Copy link

sentry-io bot commented Jul 24, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: src/sentry/integrations/slack/message_builder/issues.py

Function Unhandled Issue
build TypeError: 'NoneType' object cannot be interpreted as an integer sentry.tasks.activity.send_activi...
Event Count: 20
build Actor.InvalidActor: Cannot find a User with id=2493315 sentry.tasks.digests.deliver_...
Event Count: 1

Did you find this useful? React with a 👍 or 👎

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 24, 2024
Copy link

codecov bot commented Jul 24, 2024

Codecov Report

Attention: Patch coverage is 88.09524% with 5 lines in your changes missing coverage. Please review.

Project coverage is 78.13%. Comparing base (3ebf740) to head (e8f5bc1).
Report is 159 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #74876       +/-   ##
===========================================
+ Coverage   57.04%   78.13%   +21.08%     
===========================================
  Files        6732     6747       +15     
  Lines      300554   301140      +586     
  Branches    51704    51791       +87     
===========================================
+ Hits       171453   235294    +63841     
+ Misses     124314    59484    -64830     
- Partials     4787     6362     +1575     
Files Coverage Δ
...sentry/integrations/slack/webhooks/options_load.py 96.36% <100.00%> (+46.36%) ⬆️
src/sentry/notifications/utils/participants.py 91.50% <100.00%> (+66.69%) ⬆️
src/sentry/utils/committers.py 91.71% <ø> (+48.61%) ⬆️
src/sentry/integrations/message_builder.py 88.00% <83.33%> (+66.40%) ⬆️
...entry/integrations/slack/message_builder/issues.py 92.26% <84.00%> (+74.00%) ⬆️

... and 2079 files with indirect coverage changes

@cathteng cathteng requested a review from a team July 24, 2024 22:04
@cathteng cathteng marked this pull request as ready for review July 24, 2024 22:11
@cathteng cathteng requested review from a team as code owners July 24, 2024 22:11
Copy link
Member

@asottile-sentry asottile-sentry left a comment

Choose a reason for hiding this comment

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

nice!

@@ -584,7 +545,8 @@ def build(self, notification_uuid: str | None = None) -> SlackBlock:
# If an event is unspecified, use the tags of the latest event (if one exists).
event_for_tags = self.event or self.group.get_latest_event()

obj = self.event if self.event is not None else self.group
event_or_group: Group | GroupEvent = self.event if self.event is not None else self.group
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should need an annotation? mypy should be able to infer this union I think

Copy link
Member Author

Choose a reason for hiding this comment

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

it gets angry if i take it away

Copy link
Member

Choose a reason for hiding this comment

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

what's the error? -- does it narrow it to object (probably)? :(

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

src/sentry/integrations/slack/message_builder/issues.py Outdated Show resolved Hide resolved
Comment on lines 112 to 114
if actor.is_team and isinstance(assigned_actor, Team):
assignee_text = f"#{assigned_actor.slug}"
elif actor.is_user:
elif actor.is_user and isinstance(assigned_actor, RpcUser):
Copy link
Member

Choose a reason for hiding this comment

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

could probably just use the isinstance checks here since they should do the same thing

Comment on lines 53 to -54

raise NotImplementedError
Copy link
Member

Choose a reason for hiding this comment

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

I think I would probably change the ifs to elifs and else: raise AssertionError('unreachable')

src/sentry/integrations/slack/message_builder/issues.py Outdated Show resolved Hide resolved
Copy link
Member

@iamrajjoshi iamrajjoshi left a comment

Choose a reason for hiding this comment

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

lgtm, i wonder if we can consolidate these pure functions in message builder into a class eventually

@asottile-sentry
Copy link
Member

lgtm, i wonder if we can consolidate these pure functions in message builder into a class eventually

consolidating pure functions into a class is a bad idea -- they are pure functions and there is no reason to bring unnecessary object-orientation into this. classes make it harder to reason about, test, type, and work with. most of the mess we have today is due to excessive OO / inheritance / cuteness with classes and we'd be much better off without them

@cathteng cathteng merged commit 1d9d37b into master Jul 29, 2024
49 of 50 checks passed
@cathteng cathteng deleted the cathy/slack/type-issues-message-builder branch July 29, 2024 20:49
@cathteng cathteng added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Jul 29, 2024
@getsentry-bot
Copy link
Contributor

PR reverted: 0b20403

getsentry-bot added a commit that referenced this pull request Jul 29, 2024
This reverts commit 1d9d37b.

Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
roaga pushed a commit that referenced this pull request Jul 31, 2024
This reverts commit 1d9d37b.

Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Aug 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert Add to a merged PR to revert it (skips CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants