pub struct Binding<'a> {
pub kind: BindingKind<'a>,
pub range: TextRange,
pub scope: ScopeId,
pub context: ExecutionContext,
pub source: Option<NodeId>,
pub references: Vec<ResolvedReferenceId>,
pub exceptions: Exceptions,
pub flags: BindingFlags,
}Fields§
§kind: BindingKind<'a>§range: TextRange§scope: ScopeId§context: ExecutionContextThe context in which the Binding was created.
source: Option<NodeId>The statement in which the Binding was defined.
references: Vec<ResolvedReferenceId>The references to the Binding.
exceptions: ExceptionsThe exceptions that were handled when the Binding was defined.
flags: BindingFlagsFlags for the Binding.
Implementations§
Source§impl<'a> Binding<'a>
impl<'a> Binding<'a>
Sourcepub fn is_unused(&self) -> bool
pub fn is_unused(&self) -> bool
Return true if this Binding is unused.
This method is the opposite of Binding::is_used.
Sourcepub fn is_used(&self) -> bool
pub fn is_used(&self) -> bool
Return true if this Binding is used.
This method is the opposite of Binding::is_unused.
Sourcepub fn references(&self) -> impl Iterator<Item = ResolvedReferenceId> + '_
pub fn references(&self) -> impl Iterator<Item = ResolvedReferenceId> + '_
Returns an iterator over all references for the current Binding.
Sourcepub const fn is_explicit_export(&self) -> bool
pub const fn is_explicit_export(&self) -> bool
Return true if this Binding represents an explicit re-export
(e.g., FastAPI in from fastapi import FastAPI as FastAPI).
Sourcepub const fn is_external(&self) -> bool
pub const fn is_external(&self) -> bool
Return true if this Binding represents an external symbol
(e.g., FastAPI in from fastapi import FastAPI).
Sourcepub const fn is_alias(&self) -> bool
pub const fn is_alias(&self) -> bool
Return true if this Binding represents an aliased symbol
(e.g., app in from fastapi import FastAPI as app).
Sourcepub const fn is_nonlocal(&self) -> bool
pub const fn is_nonlocal(&self) -> bool
Sourcepub const fn is_deleted(&self) -> bool
pub const fn is_deleted(&self) -> bool
Return true if this Binding was deleted.
Sourcepub const fn is_invalid_all_format(&self) -> bool
pub const fn is_invalid_all_format(&self) -> bool
Return true if this Binding represents an assignment to __all__ with an invalid
value (e.g., __all__ = "Foo").
Sourcepub const fn is_invalid_all_object(&self) -> bool
pub const fn is_invalid_all_object(&self) -> bool
Return true if this Binding represents an assignment to __all__ that includes an
invalid member (e.g., __all__ = ["Foo", 1]).
Sourcepub const fn is_unpacked_assignment(&self) -> bool
pub const fn is_unpacked_assignment(&self) -> bool
Return true if this Binding represents an unpacked assignment (e.g., x in
(x, y) = 1, 2).
Sourcepub const fn is_unbound(&self) -> bool
pub const fn is_unbound(&self) -> bool
Return true if this Binding represents an unbound variable
(e.g., x in x = 1; del x).
Sourcepub const fn is_private_declaration(&self) -> bool
pub const fn is_private_declaration(&self) -> bool
Return true if this Binding represents an private declaration
(e.g., _x in _x = "private variable")
Sourcepub const fn in_exception_handler(&self) -> bool
pub const fn in_exception_handler(&self) -> bool
Return true if this Binding took place inside an exception handler,
e.g. y in:
try:
x = 42
except RuntimeError:
y = 42Sourcepub const fn in_assert_statement(&self) -> bool
pub const fn in_assert_statement(&self) -> bool
Return true if this Binding took place inside an assert statement,
e.g. y in:
assert (y := x**2), ySourcepub const fn is_annotated_type_alias(&self) -> bool
pub const fn is_annotated_type_alias(&self) -> bool
Sourcepub const fn is_deferred_type_alias(&self) -> bool
pub const fn is_deferred_type_alias(&self) -> bool
Sourcepub const fn is_type_alias(&self) -> bool
pub const fn is_type_alias(&self) -> bool
Return true if this Binding represents either kind of type alias
Sourcepub fn redefines(&self, existing: &Binding<'_>) -> bool
pub fn redefines(&self, existing: &Binding<'_>) -> bool
Return true if this binding “redefines” the given binding, as per Pyflake’s definition of
redefinition.
Sourcepub fn name<'b>(&self, source: &'b str) -> &'b str
pub fn name<'b>(&self, source: &'b str) -> &'b str
Returns the name of the binding (e.g., x in x = 1).
Sourcepub fn statement<'b>(&self, semantic: &SemanticModel<'b>) -> Option<&'b Stmt>
pub fn statement<'b>(&self, semantic: &SemanticModel<'b>) -> Option<&'b Stmt>
Returns the statement in which the binding was defined.
Sourcepub fn expression<'b>(&self, semantic: &SemanticModel<'b>) -> Option<&'b Expr>
pub fn expression<'b>(&self, semantic: &SemanticModel<'b>) -> Option<&'b Expr>
Returns the expression in which the binding was defined
(e.g. for the binding x in y = (x := 1), return the node representing x := 1).
This is only really applicable for assignment expressions.
Sourcepub fn parent_range(&self, semantic: &SemanticModel<'_>) -> Option<TextRange>
pub fn parent_range(&self, semantic: &SemanticModel<'_>) -> Option<TextRange>
Returns the range of the binding’s parent.
pub fn as_any_import(&self) -> Option<AnyImport<'_, 'a>>
Trait Implementations§
Source§impl<'a> FromIterator<Binding<'a>> for Bindings<'a>
impl<'a> FromIterator<Binding<'a>> for Bindings<'a>
Auto Trait Implementations§
impl<'a> Freeze for Binding<'a>
impl<'a> RefUnwindSafe for Binding<'a>
impl<'a> Send for Binding<'a>
impl<'a> Sync for Binding<'a>
impl<'a> Unpin for Binding<'a>
impl<'a> UnsafeUnpin for Binding<'a>
impl<'a> UnwindSafe for Binding<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more