Browse Source

ref: fix [return-value] mypy errors (#84433)

<!-- Describe your PR here. -->
anthony sottile 1 month ago
parent
commit
d493d88e95

+ 0 - 1
pyproject.toml

@@ -266,7 +266,6 @@ disable_error_code = [
     "misc",
     "operator",
     "override",
-    "return-value",
     "typeddict-item",
     "union-attr",
     "unreachable",

+ 1 - 1
src/sentry/api/base.py

@@ -597,7 +597,7 @@ class EnvironmentMixin:
         self, request: Request, organization_id: int
     ) -> int | None:
         environment = self._get_environment_from_request(request, organization_id)
-        return environment and environment.id
+        return environment.id if environment is not None else None
 
     def _get_environment_from_request(
         self, request: Request, organization_id: int

+ 2 - 2
src/sentry/api/endpoints/organization_events_facets_performance.py

@@ -18,7 +18,7 @@ from sentry.api.paginator import GenericOffsetPaginator
 from sentry.api.utils import handle_query_errors
 from sentry.search.events.builder.discover import DiscoverQueryBuilder
 from sentry.search.events.fields import DateArg
-from sentry.search.events.types import SnubaParams
+from sentry.search.events.types import EventsResponse, SnubaParams
 from sentry.snuba import discover
 from sentry.snuba.dataset import Dataset
 from sentry.utils.cursors import Cursor, CursorResult
@@ -379,7 +379,7 @@ def query_facet_performance(
     all_tag_keys: bool | None = None,
     tag_key: bool | None = None,
     include_count_delta: bool | None = None,
-) -> dict:
+) -> EventsResponse:
     # Dynamically sample so at least 50000 transactions are selected
     sample_start_count = 50000
     transaction_count = tag_data["count"]

+ 1 - 2
src/sentry/api/endpoints/organization_events_meta.py

@@ -1,5 +1,4 @@
 import re
-from collections.abc import Mapping
 
 import sentry_sdk
 from rest_framework.exceptions import ParseError
@@ -29,7 +28,7 @@ class OrganizationEventsMetaEndpoint(OrganizationEventsEndpointBase):
     }
     snuba_methods = ["GET"]
 
-    def get_features(self, organization: Organization, request: Request) -> Mapping[str, bool]:
+    def get_features(self, organization: Organization, request: Request) -> dict[str, bool | None]:
         feature_names = [
             "organizations:dashboards-mep",
             "organizations:mep-rollout-flag",

+ 3 - 1
src/sentry/auth/helper.py

@@ -594,7 +594,9 @@ class AuthIdentityHandler:
             # A blank character is needed to prevent an HTML span from collapsing
             return " "
 
-    def _dispatch_to_confirmation(self, is_new_account: bool) -> tuple[User | None, str]:
+    def _dispatch_to_confirmation(
+        self, is_new_account: bool
+    ) -> tuple[User | AnonymousUser | None, str]:
         if self._logged_in_user:
             return self._logged_in_user, "auth-confirm-link"
 

+ 3 - 3
src/sentry/eventstore/models.py

@@ -349,9 +349,9 @@ class BaseEvent(metaclass=abc.ABCMeta):
 
         # Get each variant's hash value, filtering out Nones
         hashes = [
-            hashes_by_variant[variant_name]
-            for variant_name in sorted_variant_names
-            if hashes_by_variant[variant_name] is not None
+            h
+            for h in (hashes_by_variant[variant_name] for variant_name in sorted_variant_names)
+            if h is not None
         ]
 
         # Write to event before returning

+ 1 - 1
src/sentry/integrations/github/blame.py

@@ -126,7 +126,7 @@ def extract_commits_from_blame_response(
     files: Sequence[SourceLineInfo],
     file_path_mapping: FilePathMapping,
     extra: dict[str, str | int | None],
-) -> Sequence[FileBlameInfo]:
+) -> list[FileBlameInfo]:
     """
     Using the file path mapping that generated the initial GraphQL query,
     this function extracts all commits from the response and maps each one

+ 10 - 5
src/sentry/integrations/github/client.py

@@ -56,8 +56,9 @@ class GithubRateLimitInfo:
 
 
 class GithubProxyClient(IntegrationProxyClient):
+    integration: Integration  # late init
+
     def _get_installation_id(self) -> str:
-        self.integration: RpcIntegration
         """
         Returns the Github App installation identifier.
         This is necessary since Github and Github Enterprise integrations store the
@@ -175,9 +176,13 @@ class GithubProxyClient(IntegrationProxyClient):
         return prepared_request
 
     def is_error_fatal(self, error: Exception) -> bool:
-        if hasattr(error.response, "text") and error.response.text:
-            if "suspended" in error.response.text:
-                return True
+        if (
+            hasattr(error, "response")
+            and hasattr(error.response, "text")
+            and error.response.text
+            and "suspended" in error.response.text
+        ):
+            return True
         return super().is_error_fatal(error)
 
 
@@ -358,7 +363,7 @@ class GitHubBaseClient(GithubProxyClient, RepositoryClient, CommitContextClient,
 
     def get_with_pagination(
         self, path: str, response_key: str | None = None, page_number_limit: int | None = None
-    ) -> Sequence[Any]:
+    ) -> list[Any]:
         """
         Github uses the Link header to provide pagination links. Github
         recommends using the provided link relations and not constructing our

+ 1 - 1
src/sentry/integrations/github/issues.py

@@ -296,7 +296,7 @@ class GitHubIssuesSpec(SourceCodeIssueIntegration):
         except Exception as e:
             self.raise_error(e)
 
-        def natural_sort_pair(pair: tuple[str, str]) -> str | int:
+        def natural_sort_pair(pair: tuple[str, str]) -> list[str | int]:
             return [
                 int(text) if text.isdecimal() else text for text in re.split("([0-9]+)", pair[0])
             ]

+ 5 - 3
src/sentry/integrations/jira/integration.py

@@ -130,8 +130,8 @@ class JiraIntegration(IssueSyncIntegration):
     def use_email_scope(cls):
         return settings.JIRA_USE_EMAIL_SCOPE
 
-    def get_organization_config(self) -> dict[str, Any]:
-        configuration = [
+    def get_organization_config(self) -> list[dict[str, Any]]:
+        configuration: list[dict[str, Any]] = [
             {
                 "name": self.outbound_status_key,
                 "type": "choice_mapper",
@@ -987,7 +987,9 @@ class JiraIntegration(IssueSyncIntegration):
             }
         )
 
-    def parse_jira_issue_metadata(self, meta: dict[str, Any]) -> list[JiraIssueTypeMetadata] | None:
+    def parse_jira_issue_metadata(
+        self, meta: dict[str, Any]
+    ) -> dict[str, JiraIssueTypeMetadata] | None:
         try:
             return JiraIssueTypeMetadata.from_jira_meta_config(meta)
         except Exception as e:

Some files were not shown because too many files changed in this diff