Skip to main content

Binding

Struct Binding 

Source
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

The ScopeId of the scope in which the Binding was defined.

§context: ExecutionContext

The 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: Exceptions

The exceptions that were handled when the Binding was defined.

§flags: BindingFlags

Flags for the Binding.

Implementations§

Source§

impl<'a> Binding<'a>

Source

pub fn is_unused(&self) -> bool

Return true if this Binding is unused.

This method is the opposite of Binding::is_used.

Source

pub fn is_used(&self) -> bool

Return true if this Binding is used.

This method is the opposite of Binding::is_unused.

Source

pub fn references(&self) -> impl Iterator<Item = ResolvedReferenceId> + '_

Returns an iterator over all references for the current Binding.

Source

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).

Source

pub const fn is_external(&self) -> bool

Return true if this Binding represents an external symbol (e.g., FastAPI in from fastapi import FastAPI).

Source

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).

Source

pub const fn is_nonlocal(&self) -> bool

Return true if this Binding represents a nonlocal. A Binding is a nonlocal if it’s declared by a nonlocal statement, or shadows a Binding declared by a nonlocal statement.

Source

pub const fn is_global(&self) -> bool

Return true if this Binding represents a global. A Binding is a global if it’s declared by a global statement, or shadows a Binding declared by a global statement.

Source

pub const fn is_deleted(&self) -> bool

Return true if this Binding was deleted.

Source

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").

Source

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]).

Source

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).

Source

pub const fn is_unbound(&self) -> bool

Return true if this Binding represents an unbound variable (e.g., x in x = 1; del x).

Source

pub const fn is_private_declaration(&self) -> bool

Return true if this Binding represents an private declaration (e.g., _x in _x = "private variable")

Source

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 = 42
Source

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), y
Source

pub const fn is_annotated_type_alias(&self) -> bool

Return true if this Binding represents a PEP 613 type alias e.g. OptString in:

from typing import TypeAlias

OptString: TypeAlias = str | None
Source

pub const fn is_deferred_type_alias(&self) -> bool

Return true if this Binding represents a PEP 695 type alias e.g. OptString in:

type OptString = str | None
Source

pub const fn is_type_alias(&self) -> bool

Return true if this Binding represents either kind of type alias

Source

pub fn redefines(&self, existing: &Binding<'_>) -> bool

Return true if this binding “redefines” the given binding, as per Pyflake’s definition of redefinition.

Source

pub fn name<'b>(&self, source: &'b str) -> &'b str

Returns the name of the binding (e.g., x in x = 1).

Source

pub fn statement<'b>(&self, semantic: &SemanticModel<'b>) -> Option<&'b Stmt>

Returns the statement in which the binding was defined.

Source

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.

Source

pub fn parent_range(&self, semantic: &SemanticModel<'_>) -> Option<TextRange>

Returns the range of the binding’s parent.

Source

pub fn as_any_import(&self) -> Option<AnyImport<'_, 'a>>

Trait Implementations§

Source§

impl<'a> Clone for Binding<'a>

Source§

fn clone(&self) -> Binding<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Binding<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> FromIterator<Binding<'a>> for Bindings<'a>

Source§

fn from_iter<T: IntoIterator<Item = Binding<'a>>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl Ranged for Binding<'_>

Source§

fn range(&self) -> TextRange

The range of this item in the source text.
Source§

fn start(&self) -> TextSize

The start offset of this item in the source text.
Source§

fn end(&self) -> TextSize

The end offset of this item in the source text.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.