Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 2026/spec/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ def has_override(u: User) -> bool:


@rule
def account_older_than(days: int, u: User) -> bool:
def account_older_than(u: User, days: int) -> bool:
return u.account_age > days


@rule
def from_country(countries: Iterable[str], u: User) -> bool:
def from_country(u: User, countries: Iterable[str]) -> bool:
return u.country in countries


@rule
def credit_score_above(threshold: int, u: User) -> bool:
def credit_score_above(u: User, threshold: int) -> bool:
return u.credit_score > threshold


Expand Down
16 changes: 9 additions & 7 deletions 2026/spec/rules.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
from __future__ import annotations

import json
from functools import wraps
from typing import Any, Callable
from typing import Any, Callable, Concatenate

# ------------------------------------------------------------
# Generic Types
# ------------------------------------------------------------

type PredicateFn[T] = Callable[[T], bool]
type RuleDef = Callable[..., bool]
type PredicateFactory[T] = Callable[..., Predicate[T]]
type RuleDef[T, **P] = Callable[Concatenate[T, P], bool]
type PredicateFactory[T, **P] = Callable[P, Predicate[T]]


# ------------------------------------------------------------
# Global Rule Registry
# ------------------------------------------------------------

RULES: dict[str, PredicateFactory[Any]] = {}
RULES: dict[str, PredicateFactory[Any, ...]] = {}


# ------------------------------------------------------------
Expand Down Expand Up @@ -59,10 +61,10 @@ def wrapper(obj: T) -> bool:



def rule[T](fn: RuleDef) -> PredicateFactory[Any]:
def rule[T, **P](fn: RuleDef[T, P]) -> PredicateFactory[T, P]:
@wraps(fn)
def wrapper(*args: Any, **kwargs: Any) -> Predicate[T]:
return Predicate(lambda obj: fn(*args, obj, **kwargs))
def wrapper(*args: P.args, **kwargs: P.kwargs) -> Predicate[T]:
return Predicate(lambda obj: fn(obj, *args, **kwargs))

RULES[fn.__name__] = wrapper
return wrapper
Expand Down