ref(issues): Convert GroupType class config to ClassVar#113423
Draft
ref(issues): Convert GroupType class config to ClassVar#113423
Conversation
`GroupType` is never instantiated in production: subclasses declare their configuration as class-level attributes (`type_id = 1001`, `slug = "foo"`, etc.) and the registry stores the classes themselves. Despite that, the base declared fields as `@dataclass(frozen=True)` instance attributes, so every access like `group_type.type_id` (where `group_type: type[GroupType]`) is really class-level access. Convert the fields to `ClassVar[T]`, preserving the same defaults. Also convert the `ReplayGroupTypeDefaults` mixin's `notification_config` for the same reason. Behavior change: `GroupType.__post_init__` was previously dead code (nothing instantiates `GroupType`), so category validation never actually ran. Move the same validation to `__init_subclass__` so it fires at subclass-definition time. Update the two tests that were constructing `GroupType(...)` (not a real production usage pattern) to define subclasses and the category-validation test to expect the failure at class-definition time. Prep work for the mypy 1.20 upgrade (#113419) — safe under 1.19.1. Agent transcript: https://claudescope.sentry.dev/share/8kuOPo_F7g0JelnKiHguToNZr0_y4AKNCOGNvydSZac
Contributor
Backend Test FailuresFailures on
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
`GroupType` is never instantiated in production — subclasses declare their configuration as class-level attributes (`type_id = 1001`, `slug = "foo"`, etc.) and the registry stores the classes themselves. Despite that, the base declared fields as `@dataclass(frozen=True)` instance attributes, so every access like `group_type.type_id` (where `group_type: type[GroupType]`) was really class-level access against an instance-level annotation.
Convert the fields to `ClassVar[T]`, preserving the same defaults. Also convert `ReplayGroupTypeDefaults.notification_config` for the same reason.
Small behavior change
`GroupType.post_init` was previously dead code — nothing instantiates `GroupType`, so the category-value validation never actually ran. Move the same validation to `init_subclass` so it fires at subclass-definition time (earlier, and actually reachable). Updates:
Why this PR exists
Prep for the mypy upgrade to 1.20.1 in #113419. 1.20.1 adds a new `[misc]` check, "Cannot access instance-only attribute on class object," and `GroupType` is the single biggest cluster of such errors in the repo. Splitting it out so the targeted reviewers only have to look at their own areas.
Safe under the current mypy (1.19.1).
Agent transcript: https://claudescope.sentry.dev/share/JFAQdL9BKvw8zOc8RROKUSNl-Xpuu8y4p4URoIp7DDk