]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
update is_precedent() annotation to accept against=None 10643/head
authorMartijn Pieters <mj@zopatista.com>
Sat, 18 Nov 2023 15:03:37 +0000 (15:03 +0000)
committerMartijn Pieters <mj@zopatista.com>
Sat, 18 Nov 2023 15:14:33 +0000 (15:14 +0000)
This is commonly passed in already by `.self_group()` calls where
`against` defaults to `None`.

Handle `against is None` explicitly as the standard type stubs only
accepts the key type for the second argument to `dict.get()`.

lib/sqlalchemy/sql/operators.py

index 6402d0fd1b2ee9dfaff0102c72e5f6872caf2b2e..1d3f2f483f69e4af2c2888fb4545ed3e2962fc96 100644 (file)
@@ -2582,9 +2582,13 @@ _PRECEDENCE: Dict[OperatorType, int] = {
 }
 
 
-def is_precedent(operator: OperatorType, against: OperatorType) -> bool:
+def is_precedent(
+    operator: OperatorType, against: Optional[OperatorType]
+) -> bool:
     if operator is against and is_natural_self_precedent(operator):
         return False
+    elif against is None:
+        return True
     else:
         return bool(
             _PRECEDENCE.get(