Browse Source

ref: eliminate cast(...) from HC create_delegation (#58367)

create_delegation is a funny not-quite-typesafe proxy object so we
"fake" that it's the self class (it could be with a little more work and
less wrapper classes -- but that's for another day!). this uses the
`Self` type to avoid cargo culting more `cast` usage (which we should be
cutting down to zero)
anthony sottile 1 year ago
parent
commit
d9750e215b

+ 2 - 3
src/sentry/hybridcloud/rpc/services/caching/service.py

@@ -14,7 +14,6 @@ from typing import (
     Type,
     TypeVar,
     Union,
-    cast,
 )
 
 import pydantic
@@ -108,7 +107,7 @@ def back_with_silo_cache(
     return wrapper
 
 
-region_caching_service = cast(RegionCachingService, RegionCachingService.create_delegation())
+region_caching_service = RegionCachingService.create_delegation()
 
 
 class ControlCachingService(RpcService):
@@ -127,4 +126,4 @@ class ControlCachingService(RpcService):
         pass
 
 
-control_caching_service = cast(ControlCachingService, ControlCachingService.create_delegation())
+control_caching_service = ControlCachingService.create_delegation()

+ 3 - 4
src/sentry/hybridcloud/rpc_services/control_organization_provisioning/service.py

@@ -3,7 +3,7 @@
 # in modules such as this one where hybrid cloud data models or service classes are
 # defined, because we want to reflect on type annotations and avoid forward references.
 from abc import abstractmethod
-from typing import Optional, cast
+from typing import Optional
 
 from sentry.hybridcloud.rpc_services.control_organization_provisioning.model import (
     RpcOrganizationSlugReservation,
@@ -87,7 +87,6 @@ class ControlOrganizationProvisioningRpcService(RpcService):
         return DatabaseBackedControlOrganizationProvisioningService()
 
 
-control_organization_provisioning_rpc_service: ControlOrganizationProvisioningRpcService = cast(
-    ControlOrganizationProvisioningRpcService,
-    ControlOrganizationProvisioningRpcService.create_delegation(),
+control_organization_provisioning_rpc_service = (
+    ControlOrganizationProvisioningRpcService.create_delegation()
 )

+ 2 - 4
src/sentry/hybridcloud/rpc_services/region_organization_provisioning/service.py

@@ -1,5 +1,4 @@
 from abc import abstractmethod
-from typing import cast
 
 from sentry.hybridcloud.rpc_services.control_organization_provisioning import (
     RpcOrganizationSlugReservation,
@@ -70,7 +69,6 @@ class RegionOrganizationProvisioningRpcService(RpcService):
         return DatabaseBackedRegionOrganizationProvisioningRpcService()
 
 
-region_organization_provisioning_rpc_service: RegionOrganizationProvisioningRpcService = cast(
-    RegionOrganizationProvisioningRpcService,
-    RegionOrganizationProvisioningRpcService.create_delegation(),
+region_organization_provisioning_rpc_service = (
+    RegionOrganizationProvisioningRpcService.create_delegation()
 )

+ 2 - 2
src/sentry/services/hybrid_cloud/app/service.py

@@ -4,7 +4,7 @@
 # defined, because we want to reflect on type annotations and avoid forward references.
 
 import abc
-from typing import Any, List, Mapping, Optional, cast
+from typing import Any, List, Mapping, Optional
 
 from sentry.services.hybrid_cloud.app import (
     RpcAlertRuleActionResult,
@@ -153,4 +153,4 @@ class AppService(RpcService):
         pass
 
 
-app_service = cast(AppService, AppService.create_delegation())
+app_service = AppService.create_delegation()

+ 2 - 2
src/sentry/services/hybrid_cloud/auth/service.py

@@ -4,7 +4,7 @@
 # defined, because we want to reflect on type annotations and avoid forward references.
 
 import abc
-from typing import Any, List, Mapping, Optional, cast
+from typing import Any, List, Mapping, Optional
 
 from sentry.services.hybrid_cloud.auth import (
     AuthenticationContext,
@@ -118,4 +118,4 @@ class AuthService(RpcService):
         pass
 
 
-auth_service: AuthService = cast(AuthService, AuthService.create_delegation())
+auth_service = AuthService.create_delegation()

+ 2 - 2
src/sentry/services/hybrid_cloud/hook/service.py

@@ -4,7 +4,7 @@
 # defined, because we want to reflect on type annotations and avoid forward references.
 
 import abc
-from typing import List, Optional, cast
+from typing import List, Optional
 
 from sentry.services.hybrid_cloud.hook import RpcServiceHook
 from sentry.services.hybrid_cloud.region import ByOrganizationId
@@ -50,4 +50,4 @@ class HookService(RpcService):
         pass
 
 
-hook_service: HookService = cast(HookService, HookService.create_delegation())
+hook_service = HookService.create_delegation()

+ 2 - 2
src/sentry/services/hybrid_cloud/identity/service.py

@@ -4,7 +4,7 @@
 # defined, because we want to reflect on type annotations and avoid forward references.
 
 from abc import abstractmethod
-from typing import Any, List, Optional, cast
+from typing import Any, List, Optional
 
 from sentry.services.hybrid_cloud.identity import RpcIdentity, RpcIdentityProvider
 from sentry.services.hybrid_cloud.identity.model import IdentityFilterArgs
@@ -91,4 +91,4 @@ class IdentityService(RpcService):
         pass
 
 
-identity_service: IdentityService = cast(IdentityService, IdentityService.create_delegation())
+identity_service = IdentityService.create_delegation()

+ 2 - 4
src/sentry/services/hybrid_cloud/import_export/service.py

@@ -4,7 +4,7 @@
 # defined, because we want to reflect on type annotations and avoid forward references.
 
 from abc import abstractmethod
-from typing import List, Optional, Set, cast
+from typing import List, Optional, Set
 
 from sentry.services.hybrid_cloud.import_export.model import (
     RpcExportResult,
@@ -61,6 +61,4 @@ class ImportExportService(RpcService):
         pass
 
 
-import_export_service: ImportExportService = cast(
-    ImportExportService, ImportExportService.create_delegation()
-)
+import_export_service = ImportExportService.create_delegation()

+ 2 - 4
src/sentry/services/hybrid_cloud/integration/service.py

@@ -5,7 +5,7 @@
 
 from abc import abstractmethod
 from datetime import datetime
-from typing import Any, Dict, List, Optional, Tuple, Union, cast
+from typing import Any, Dict, List, Optional, Tuple, Union
 
 from sentry.models.integrations.organization_integration import (
     OrganizationIntegration,
@@ -287,6 +287,4 @@ class IntegrationService(RpcService):
         pass
 
 
-integration_service: IntegrationService = cast(
-    IntegrationService, IntegrationService.create_delegation()
-)
+integration_service = IntegrationService.create_delegation()

+ 2 - 2
src/sentry/services/hybrid_cloud/issue/service.py

@@ -5,7 +5,7 @@
 
 
 from abc import abstractmethod
-from typing import Optional, cast
+from typing import Optional
 
 from sentry.services.hybrid_cloud.issue.model import RpcGroupShareMetadata
 from sentry.services.hybrid_cloud.region import ByOrganizationSlug, ByRegionName
@@ -46,4 +46,4 @@ class IssueService(RpcService):
         pass
 
 
-issue_service = cast(IssueService, IssueService.create_delegation())
+issue_service = IssueService.create_delegation()

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