add rule permission reflected operation support (#872)

Feature: 添加 Rule, Permission 反向位运算支持
This commit is contained in:
Ju4tCode
2022-03-17 21:11:37 +08:00
committed by GitHub
parent 06f8dde33c
commit 02de6fd266
5 changed files with 196 additions and 2 deletions

View File

@ -91,5 +91,13 @@ class Rule:
else:
return Rule(*self.checkers, other)
def __or__(self, other) -> NoReturn:
def __rand__(self, other: Optional[Union["Rule", T_RuleChecker]]) -> "Rule":
if other is None:
return self
elif isinstance(other, Rule):
return Rule(*other.checkers, *self.checkers)
else:
return Rule(other, *self.checkers)
def __or__(self, other: object) -> NoReturn:
raise RuntimeError("Or operation between rules is not allowed.")