diff options
author | Frederick Muriuki Muriithi | 2025-07-23 01:19:52 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-07-23 16:59:27 -0500 |
commit | df45a172cdc0b012d4fad8363531fd1caa5c7f4b (patch) | |
tree | aa2880cc5533d13ee2d8f97a1efe87a2a146199c | |
parent | d3c04823c3e9d2be0ac8f81f9266db3cdb509819 (diff) | |
download | gn-libs-df45a172cdc0b012d4fad8363531fd1caa5c7f4b.tar.gz |
Improve definition of types.
-rw-r--r-- | gn_libs/privileges.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/gn_libs/privileges.py b/gn_libs/privileges.py index 47cb735..a515970 100644 --- a/gn_libs/privileges.py +++ b/gn_libs/privileges.py @@ -1,11 +1,13 @@ """Utilities for handling privileges.""" -from typing import Union, TypeAlias +from typing import Union, Sequence, TypeAlias -PrivilegesList = tuple[str, ...] -CheckObj = tuple[str, PrivilegesList] # where the first item is either "OR" or "AND" -Checks: TypeAlias = Union[ - CheckObj, - tuple[str, tuple['Checks', ...]]] +Operator: TypeAlias = str # Valid operators: "AND", "OR" +Privilege: TypeAlias = str +PrivilegesList: TypeAlias = Sequence[Privilege] +ParseTree = tuple[Operator, + # Leaves (`PrivilegesList` objects) on the left, + # trees (`ParseTree` objects) on the right + Union[PrivilegesList, tuple[PrivilegesList, 'ParseTree']]] class SpecificationValueError(ValueError): @@ -13,7 +15,7 @@ class SpecificationValueError(ValueError): pass -def parse(spec: str) -> Checks: +def parse(spec: str) -> ParseTree: """Parse a string specification for privileges and return a tree of data objects of the form (<operator> (<check>))""" # if(spec.strip() == ""): |