squabble.rule module¶
-
class
squabble.rule.
Registry
[source]¶ Bases:
object
Singleton instance used to keep track of all rules.
Any class that inherits from
squabble.rules.BaseRule
will automatically be registered to the registry.-
static
all
()[source]¶ Return an iterator over all known rule metadata. Equivalent to calling
get_meta()
for all registered rules.
-
static
get_class
(name)[source]¶ Return class for given rule name in the registry.
If no rule exists in the registry named
name
,UnknownRuleException
will be thrown.
-
static
-
squabble.rule.
load_rules
(plugin_paths=None)[source]¶ Load built in rules as well as any custom rules contained in the directories in plugin_paths.
-
squabble.rule.
node_visitor
(fn)[source]¶ Helper decorator to make it easier to register callbacks for AST nodes. Effectively creates the partial function automatically so there’s no need for a lambda.
Wraps
fn
to pass inself
,context
, andnode
when the callback is called.>>> from squabble.rules import BaseRule >>> class SomeRule(BaseRule): ... def enable(self, ctx, config): ... # These are equivalent ... ctx.register('foo', self.check_foo(x=1)) ... ctx.register('bar', lambda c, n: self.check_bar(c, n, x=1)) ... ... @node_visitor ... def check_foo(self, context, node, x): ... pass ... ... def check_bar(self, context, node, x): ... pass