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:
objectBinding 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.QualifiedNameProvider[source]¶
Bases:
objectResolves names to their qualified form based on imports.
- class rude.providers.Scope¶
Bases:
objectScope 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
ScopeTypeenum).
- uses¶
Get uses list for Python access.
- class rude.providers.ScopeProvider[source]¶
Bases:
objectProvides 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}")