Skip to content

Commit c62dbad

Browse files
committed
changed using union for python 3.8
1 parent 0f70940 commit c62dbad

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

mergin/client.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import re
1717
import typing
1818
import warnings
19+
from enum import Enum
20+
from typing import Optional, Type, Union
1921

2022
from .common import (
2123
ClientError,
@@ -1319,7 +1321,7 @@ def create_user(
13191321
email: str,
13201322
password: str,
13211323
workspace_id: int,
1322-
workspace_role: str | WorkspaceRole,
1324+
workspace_role: Union[str, WorkspaceRole],
13231325
username: str = None,
13241326
notify_user: bool = False,
13251327
) -> dict:
@@ -1367,7 +1369,11 @@ def list_workspace_members(self, workspace_id: int) -> typing.List[dict]:
13671369
return json.load(resp)
13681370

13691371
def update_workspace_member(
1370-
self, workspace_id: int, user_id: int, workspace_role: str | WorkspaceRole, reset_projects_roles: bool = False
1372+
self,
1373+
workspace_id: int,
1374+
user_id: int,
1375+
workspace_role: Union[str, WorkspaceRole],
1376+
reset_projects_roles: bool = False,
13711377
) -> dict:
13721378
"""
13731379
Update workspace role of a workspace member, optionally resets the projects role
@@ -1402,7 +1408,7 @@ def list_project_collaborators(self, project_id: str) -> typing.List[dict]:
14021408
project_collaborators = self.get(f"v2/projects/{project_id}/collaborators")
14031409
return json.load(project_collaborators)
14041410

1405-
def add_project_collaborator(self, project_id: str, user: str, project_role: ProjectRole | str) -> dict:
1411+
def add_project_collaborator(self, project_id: str, user: str, project_role: Union[str, ProjectRole]) -> dict:
14061412
"""
14071413
Add a user to project collaborators and grant them a project role.
14081414
Fails if user is already a member of the project.
@@ -1419,7 +1425,7 @@ def add_project_collaborator(self, project_id: str, user: str, project_role: Pro
14191425
project_collaborator = self.post(f"v2/projects/{project_id}/collaborators", params, json_headers)
14201426
return json.load(project_collaborator)
14211427

1422-
def update_project_collaborator(self, project_id: str, user_id: int, project_role: ProjectRole | str) -> dict:
1428+
def update_project_collaborator(self, project_id: str, user_id: int, project_role: Union[str, ProjectRole]) -> dict:
14231429
"""
14241430
Update project role of the existing project collaborator.
14251431
Fails if user is not a member of the project yet.
@@ -1506,7 +1512,7 @@ def send_logs(
15061512
request = urllib.request.Request(url, data=payload, headers=header)
15071513
return self._do_request(request)
15081514

1509-
def create_invitation(self, workspace_id: int, email: str, workspace_role: str | WorkspaceRole):
1515+
def create_invitation(self, workspace_id: int, email: str, workspace_role: Union[str, WorkspaceRole]):
15101516
"""
15111517
Create invitation to workspace for specific role
15121518
"""

mergin/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from datetime import datetime
88
from pathlib import Path
99
import tempfile
10+
from enum import Enum
11+
from typing import Optional, Type, Union
1012
from .common import ClientError, WorkspaceRole
1113

1214

@@ -311,7 +313,7 @@ def cleanup_tmp_dir(mp, tmp_dir: tempfile.TemporaryDirectory):
311313
mp.log.error(f"Error during tmp dir cleanup: {tmp_dir.name}: {e}")
312314

313315

314-
def normalize_role(role, enum_cls):
316+
def normalize_role(role: Union[str, Enum], enum_cls: Type[Enum]) -> Optional[Enum]:
315317
if isinstance(role, enum_cls):
316318
return role
317319

0 commit comments

Comments
 (0)