Metadata Providers API

Metadata providers give rules access to semantic information computed once per file. See the Metadata providers guide for usage examples and the Semantic Analysis API page for the Rust-powered SemanticModel API.

Metadata providers for advanced analysis.

Providers compute additional information about the AST that rules can use for more sophisticated checks. They are lazy-computed and cached.

Available providers: - ParentProvider: Track parent of each node - ScopeProvider: Scope and binding analysis (Rust-based, high-performance) - QualifiedNameProvider: Resolve names to their qualified form

class rude.providers.Binding

Bases: object

Binding data stored in arena (immutable after construction).

Represents a variable binding with its location, scope, and usage information.

is_exception_handler

Check if this binding is an exception handler variable.

is_global

Check if this binding has global declaration.

is_import

Check if this binding is an import.

is_nonlocal

Check if this binding has nonlocal declaration.

is_parameter

Check if this binding is a function parameter.

references

Get references list for Python access.

class rude.providers.ParentProvider[source]

Bases: object

Provides parent node lookup.

__init__()[source]
Return type:

None

class rude.providers.QualifiedNameProvider[source]

Bases: object

Resolves names to their qualified form based on imports.

__init__()[source]
Return type:

None

class rude.providers.Scope

Bases: object

Scope data stored in arena (immutable after construction).

bindings

Get the bindings dict for Python access.

children

Get children list for Python access.

globals

Get globals set for Python access.

nonlocals

Get nonlocals set for Python access.

type

Scope type as an integer (see ScopeType enum).

uses

Get uses list for Python access.

class rude.providers.ScopeProvider[source]

Bases: object

Provides scope and binding analysis using Rust-based analyzer.

Uses a single call to analyze_source() which parses and traverses the AST entirely in Rust for maximum performance.

Usage:

sp = ctx.get_metadata(ScopeProvider)
m = sp.model

# Access module scope
scope = m.scopes[m.module_scope]

# Check unused bindings
for name, bid in scope.bindings.items():
    binding = m.bindings[bid]
    if not binding.references:
        print(f"Unused: {name}")
__init__()[source]
Return type:

None

classmethod from_model(model)[source]

Create a ScopeProvider with a pre-built SemanticModel.

Parameters:

model (SemanticModel)

Return type:

Self

class rude.providers.ScopeType[source]

Bases: IntEnum

Scope type enumeration - compatible with Rust constants.

__new__(value)