fix(typing): Replace type: ignore comments with proper type fixes#107721
Closed
JoshFerge wants to merge 1 commit into
Closed
fix(typing): Replace type: ignore comments with proper type fixes#107721JoshFerge wants to merge 1 commit into
JoshFerge wants to merge 1 commit into
Conversation
- Create get_relay_from_request() and get_relay_request_data() helpers in authentication.py for typed relay attribute access - Use getattr() for dynamic request.organization access - Use is_user_signed_request() for user_from_signed_request checks - Add None guards before ORM lookups with possibly-None values - Fix isinstance check for str keys in base_query_set order_by - Remove unreachable code path (EventData.event_id is required) - Remove invalid select_related on ManyToManyField - Use cast() for Django _meta.get_field() return type
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Stacked on #107710. Fixes the
# type: ignorecomments that were added during the mypy 1.19.1 upgrade by replacing them with proper type-safe solutions.Changes by category
attr-definedfixes (relay, organization, user_from_signed_request):get_relay_from_request()andget_relay_request_data()typed helpers inauthentication.pyrequest.relay/request.relay_request_datagetattr()forrequest.organizationaccess (returnsAny, satisfies mypy)is_user_signed_request()helper foruser_from_signed_requestmiscfixes (ORM lookups with possibly-None values):.get(id=...)calls where the ID could be Noneassert ... is not Nonefor authenticated user IDs and organization IDsrequest.GET.get("id")into a variable to help mypy narrow the typefilter(project=project)tofilter(project_id=project.id)for HybridCloudForeignKeyarg-typefix (base_query_set.py):isinstance(col, str)check before dict lookup, properly narrowingstr | Combinableunreachablefix (delayed_processing.py):instance_data.get("event_id")toinstance_data["event_id"]sinceevent_idis a required key in theEventDataTypedDict — the None check was correctly flagged as unreachableOther fixes:
select_related()on a ManyToManyField (uptime subscriptions)cast()for Django_meta.get_field()return type in test fixture# type: ignore[no-redef]for annotation shadowing model field (genuine mypy limitation)Remaining type: ignore
One
# type: ignore[no-redef]remains inworkflow_group_history_serializer.py— this is a known mypy limitation where.annotate(detector_id=...)shadows an existing model field name.Test plan
mypypasses on all 21 changed files with 0 errors