π OpenHands: AI-Driven Development
Fix enterprise mypy type checking to catch type mismatches (#13140)
Rohit Malhotra039e208167a7
diff --git a/enterprise/dev_config/python/.pre-commit-config.yaml b/enterprise/dev_config/python/.pre-commit-config.yamlindex e2a2564455..c0925363a4 100644--- a/enterprise/dev_config/python/.pre-commit-config.yaml+++ b/enterprise/dev_config/python/.pre-commit-config.yaml@@ -50,8 +50,10 @@ repos:- ./- stripe==11.5.0- pygithub==2.6.1- # To see gaps add `--html-report mypy-report/`- entry: mypy --config-file enterprise/dev_config/python/mypy.ini enterprise/+ # Use -p (package) to avoid dual module name conflict when using MYPYPATH+ # MYPYPATH=enterprise allows resolving bare imports like "from integrations.xxx"+ # Note: tests package excluded to avoid conflict with core openhands tests+ entry: bash -c 'MYPYPATH=enterprise mypy --config-file enterprise/dev_config/python/mypy.ini -p integrations -p server -p storage -p sync -p experiments'always_run: truepass_filenames: falsefiles: ^enterprise/diff --git a/enterprise/dev_config/python/mypy.ini b/enterprise/dev_config/python/mypy.iniindex c6c1dfc365..f7dc2002a3 100644--- a/enterprise/dev_config/python/mypy.ini+++ b/enterprise/dev_config/python/mypy.ini@@ -2,7 +2,6 @@warn_unused_configs = Trueignore_missing_imports = Truecheck_untyped_defs = True-explicit_package_bases = Truewarn_unreachable = Truewarn_redundant_casts = Trueno_implicit_optional = Truediff --git a/enterprise/integrations/github/github_manager.py b/enterprise/integrations/github/github_manager.pyindex ae482f617b..6e653571cb 100644--- a/enterprise/integrations/github/github_manager.py+++ b/enterprise/integrations/github/github_manager.py@@ -310,7 +310,10 @@ class GithubManager(Manager[GithubViewType]):issue.create_comment(message)else:- logger.warning('Unsupported location')+ # Catch any new types added to GithubViewType that aren't handled above+ logger.warning( # type: ignore[unreachable]+ f'Unsupported github_view type: {type(github_view).__name__}'+ )returnasync def start_job(self, github_view: GithubViewType) -> None:diff --git a/enterprise/server/routes/org_invitation_models.py b/enterprise/server/routes/org_invitation_models.pyindex 3852959a68..0c04c6de06 100644--- a/enterprise/server/routes/org_invitation_models.py+++ b/enterprise/server/routes/org_invitation_models.py@@ -76,7 +76,7 @@ class InvitationResponse(BaseModel):inviter_email: str | None = None@classmethod- def from_invitation(+ async def from_invitation(cls,invitation: OrgInvitation,inviter_email: str | None = None,@@ -94,7 +94,7 @@ class InvitationResponse(BaseModel):if invitation.role:role_name = invitation.role.nameelif invitation.role_id:- role = RoleStore.get_role_by_id(invitation.role_id)+ role = await RoleStore.get_role_by_id(invitation.role_id)role_name = role.name if role else ''return cls(diff --git a/enterprise/server/routes/org_invitations.py b/enterprise/server/routes/org_invitations.pyindex 3349d600ac..771b78e91f 100644--- a/enterprise/server/routes/org_invitations.py+++ b/enterprise/server/routes/org_invitations.py@@ -91,8 +91,11 @@ async def create_invitation(},)+ successful_responses = [+ await InvitationResponse.from_invitation(inv) for inv in successful+ ]return BatchInvitationResponse(- successful=[InvitationResponse.from_invitation(inv) for inv in successful],+ successful=successful_responses,failed=[InvitationFailure(email=email, error=error) for email, error in failed],diff --git a/enterprise/server/routes/orgs.py b/enterprise/server/routes/orgs.pyindex f67b1f45f2..a39f959864 100644--- a/enterprise/server/routes/orgs.py+++ b/enterprise/server/routes/orgs.py@@ -781,7 +781,7 @@ async def get_org_members()if not success:- error_map = {+ error_map: dict[str | None, tuple[int, str]] = {'not_a_member': (status.HTTP_403_FORBIDDEN,'You are not a member of this organization',@@ -790,9 +790,14 @@ async def get_org_members(status.HTTP_400_BAD_REQUEST,'Invalid page_id format',),+ None: (+ status.HTTP_500_INTERNAL_SERVER_ERROR,+ 'An error occurred',+ ),}status_code, detail = error_map.get(- error_code, (status.HTTP_500_INTERNAL_SERVER_ERROR, 'An error occurred')+ error_code,+ (status.HTTP_500_INTERNAL_SERVER_ERROR, 'An error occurred'),)raise HTTPException(status_code=status_code, detail=detail)@@ -900,7 +905,7 @@ async def remove_org_member()if not success:- error_map = {+ error_map: dict[str | None, tuple[int, str]] = {'not_a_member': (status.HTTP_403_FORBIDDEN,'You are not a member of this organization',@@ -925,9 +930,14 @@ async def remove_org_member(status.HTTP_500_INTERNAL_SERVER_ERROR,'Failed to remove member',),+ None: (+ status.HTTP_500_INTERNAL_SERVER_ERROR,+ 'An error occurred',+ ),}status_code, detail = error_map.get(- error, (status.HTTP_500_INTERNAL_SERVER_ERROR, 'An error occurred')+ error,+ (status.HTTP_500_INTERNAL_SERVER_ERROR, 'An error occurred'),)raise HTTPException(status_code=status_code, detail=detail)