From 6f51b8d8984b29d4e39d3fa75f11d243507876be Mon Sep 17 00:00:00 2001 From: Kurt Schwehr Date: Mon, 21 Oct 2024 12:23:26 -0700 Subject: [PATCH] `commands._apply_permissions()`: Do a better job of convincing pytype that the typing is correct. PiperOrigin-RevId: 688230061 --- python/ee/cli/commands.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/python/ee/cli/commands.py b/python/ee/cli/commands.py index 99a5a0cc6..fcb86026e 100644 --- a/python/ee/cli/commands.py +++ b/python/ee/cli/commands.py @@ -569,27 +569,29 @@ def _apply_permissions( """Applies the given permission edits to the given acl.""" for user, role in permissions.items(): if self._is_all_users(user): - acl[ALL_USERS_CAN_READ] = (role == 'R') + acl[ALL_USERS_CAN_READ] = role == 'R' else: + readers = acl[READERS] + writers = acl[WRITERS] # Make pytype understand the types. - assert isinstance(acl[READERS], list) - assert isinstance(acl[WRITERS], list) + assert isinstance(readers, list) + assert isinstance(writers, list) if role == 'R': - if user not in acl[READERS]: - acl[READERS].append(user) - if user in acl[WRITERS]: - acl[WRITERS].remove(user) + if user not in readers: + readers.append(user) + if user in writers: + writers.remove(user) elif role == 'W': - if user in acl[READERS]: - acl[READERS].remove(user) - if user not in acl[WRITERS]: - acl[WRITERS].append(user) + if user in readers: + readers.remove(user) + if user not in writers: + writers.append(user) elif role == 'D': - if user in acl[READERS]: - acl[READERS].remove(user) - if user in acl[WRITERS]: - acl[WRITERS].remove(user) + if user in readers: + readers.remove(user) + if user in writers: + writers.remove(user) def _is_all_users(self, user: str) -> bool: """Determines if a user name represents the special "all users" entity."""