Skip to content

Conversation

@DanChov
Copy link
Contributor

@DanChov DanChov commented Jan 5, 2026

This PR adds a small helper function to normalize role inputs so callers can pass either a role Enum instance or a string (case/whitespace-insensitive). Invalid inputs return None, allowing the caller to handle validation consistently.

solves: #265

@DanChov DanChov requested review from MarcelGeo, harminius and varmar05 and removed request for MarcelGeo and harminius January 5, 2026 15:10
Copy link
Contributor

@harminius harminius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ellegant 👍

Copy link
Contributor

@varmar05 varmar05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just some minor suggestions.



def test_string_roles():
assert normalize_role("guest", WorkspaceRole) == WorkspaceRole.GUEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use pytest parametrize

self.check_collaborators_members_support()
role_enum = normalize_role(workspace_role, WorkspaceRole)
if role_enum is None:
raise ValueError("bad role")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create more user friendly message, e.g. f'Invalid role: {workspace_role}'

mp.log.error(f"Error during tmp dir cleanup: {tmp_dir.name}: {e}")


def normalize_role(role: Union[str, Enum], enum_cls: Type[Enum]) -> Optional[Enum]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some docstring

"""
self.check_collaborators_members_support()

role_enum = normalize_role(workspace_role, WorkspaceRole)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to get rid of repeated code you can try to wrap this up in some decorator which would make sure that arg would be always Enum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants