pub struct Arguments {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
pub args: Box<[Expr]>,
pub keywords: Box<[Keyword]>,
}Expand description
An AST node used to represent the arguments passed to a function call or class definition.
For example, given:
foo(1, 2, 3, bar=4, baz=5)The Arguments node would span from the left to right parentheses (inclusive), and contain
the arguments and keyword arguments in the order they appear in the source code.
Similarly, given:
class Foo(Bar, baz=1, qux=2):
passThe Arguments node would again span from the left to right parentheses (inclusive), and
contain the Bar argument and the baz and qux keyword arguments in the order they
appear in the source code.
In the context of a class definition, the Python-style AST refers to the arguments as bases,
as they represent the “explicitly specified base classes”, while the keyword arguments are
typically used for metaclass, with any additional arguments being passed to the metaclass.
Fields§
§range: TextRange§node_index: AtomicNodeIndex§args: Box<[Expr]>§keywords: Box<[Keyword]>Implementations§
Source§impl Arguments
impl Arguments
Sourcepub fn find_keyword(&self, keyword_name: &str) -> Option<&Keyword>
pub fn find_keyword(&self, keyword_name: &str) -> Option<&Keyword>
Sourcepub fn find_positional(&self, position: usize) -> Option<&Expr>
pub fn find_positional(&self, position: usize) -> Option<&Expr>
Return the positional argument at the given index, or None if no such argument exists.
Sourcepub fn find_argument_value(&self, name: &str, position: usize) -> Option<&Expr>
pub fn find_argument_value(&self, name: &str, position: usize) -> Option<&Expr>
Return the value for the argument with the given name or at the given position, or None if no such
argument exists. Used to retrieve argument values that can be provided either as keyword or
positional arguments.
Sourcepub fn find_argument(
&self,
name: &str,
position: usize,
) -> Option<ArgOrKeyword<'_>>
pub fn find_argument( &self, name: &str, position: usize, ) -> Option<ArgOrKeyword<'_>>
Return the argument with the given name or at the given position, or None if no such
argument exists. Used to retrieve arguments that can be provided either as keyword or
positional arguments.
Sourcepub fn arguments_source_order(&self) -> ArgumentsSourceOrder<'_> ⓘ
pub fn arguments_source_order(&self) -> ArgumentsSourceOrder<'_> ⓘ
Return the positional and keyword arguments in the order of declaration.
Positional arguments are generally before keyword arguments, but star arguments are an exception:
class A(*args, a=2, *args2, **kwargs):
pass
f(*args, a=2, *args2, **kwargs)where *args and args2 are args while a=1 and kwargs are keywords.
If you would just chain args and keywords the call would get reordered which we don’t
want. This function instead “merge sorts” them into the correct order.
Note that the order of evaluation is always first args, then keywords:
def f(*args, **kwargs):
pass
def g(x):
print(x)
return x
f(*g([1]), a=g(2), *g([3]), **g({"4": 5}))Output:
[1]
[3]
2
{'4': 5}pub fn inner_range(&self) -> TextRange
pub fn l_paren_range(&self) -> TextRange
pub fn r_paren_range(&self) -> TextRange
Trait Implementations§
Source§impl<'a> From<&'a Arguments> for AnyNodeRef<'a>
impl<'a> From<&'a Arguments> for AnyNodeRef<'a>
Source§fn from(node: &'a Arguments) -> AnyNodeRef<'a>
fn from(node: &'a Arguments) -> AnyNodeRef<'a>
Source§impl<'a> From<&'a Arguments> for AnyRootNodeRef<'a>
impl<'a> From<&'a Arguments> for AnyRootNodeRef<'a>
Source§fn from(node: &'a Arguments) -> AnyRootNodeRef<'a>
fn from(node: &'a Arguments) -> AnyRootNodeRef<'a>
Source§impl<'a> From<&'a Arguments> for ComparableArguments<'a>
impl<'a> From<&'a Arguments> for ComparableArguments<'a>
Source§impl HasNodeIndex for Arguments
impl HasNodeIndex for Arguments
Source§fn node_index(&self) -> &AtomicNodeIndex
fn node_index(&self) -> &AtomicNodeIndex
AtomicNodeIndex for this node.Source§impl<'a> TryFrom<AnyRootNodeRef<'a>> for &'a Arguments
impl<'a> TryFrom<AnyRootNodeRef<'a>> for &'a Arguments
impl StructuralPartialEq for Arguments
Auto Trait Implementations§
impl !Freeze for Arguments
impl RefUnwindSafe for Arguments
impl Send for Arguments
impl Sync for Arguments
impl Unpin for Arguments
impl UnsafeUnpin for Arguments
impl UnwindSafe for Arguments
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