pub struct Parameters {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
pub posonlyargs: Vec<ParameterWithDefault>,
pub args: Vec<ParameterWithDefault>,
pub vararg: Option<Box<Parameter>>,
pub kwonlyargs: Vec<ParameterWithDefault>,
pub kwarg: Option<Box<Parameter>>,
}Expand description
An alternative type of AST arguments. This is ruff_python_parser-friendly and human-friendly definition of function arguments.
This form also has advantage to implement pre-order traverse.
defaults and kw_defaults fields are removed and the default values are placed under each ParameterWithDefault typed argument.
vararg and kwarg are still typed as arg because they never can have a default value.
The original Python-style AST type orders kwonlyargs fields by default existence; Parameters has location-ordered kwonlyargs fields.
NOTE: This type differs from the original Python AST. See: arguments.
Fields§
§range: TextRange§node_index: AtomicNodeIndex§posonlyargs: Vec<ParameterWithDefault>§args: Vec<ParameterWithDefault>§vararg: Option<Box<Parameter>>§kwonlyargs: Vec<ParameterWithDefault>§kwarg: Option<Box<Parameter>>Implementations§
Source§impl Parameters
impl Parameters
Sourcepub fn iter_non_variadic_params(
&self,
) -> impl Iterator<Item = &ParameterWithDefault>
pub fn iter_non_variadic_params( &self, ) -> impl Iterator<Item = &ParameterWithDefault>
Returns an iterator over all non-variadic parameters included in this Parameters node.
The variadic parameters (.vararg and .kwarg) can never have default values;
non-variadic parameters sometimes will.
Sourcepub fn find(&self, name: &str) -> Option<&ParameterWithDefault>
pub fn find(&self, name: &str) -> Option<&ParameterWithDefault>
Returns the ParameterWithDefault with the given name, or None if no such ParameterWithDefault exists.
Sourcepub fn index(&self, name: &str) -> Option<usize>
pub fn index(&self, name: &str) -> Option<usize>
Returns the index of the parameter with the given name
Sourcepub fn iter(&self) -> ParametersIterator<'_> ⓘ
pub fn iter(&self) -> ParametersIterator<'_> ⓘ
Returns an iterator over all parameters included in this Parameters node.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the total number of parameters included in this Parameters node.
Sourcepub fn includes(&self, name: &str) -> bool
pub fn includes(&self, name: &str) -> bool
Returns true if a parameter with the given name is included in this Parameters.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the Parameters is empty.
Sourcepub fn iter_source_order(&self) -> ParametersSourceOrderIterator<'_> ⓘ
pub fn iter_source_order(&self) -> ParametersSourceOrderIterator<'_> ⓘ
Returns an iterator over all parameters in source order.
This differs from Parameters::iter which returns parameters
in type-based order (positional-only, regular, variadic, keyword-only,
keyword). For well-formed Python the two orderings are identical, but
error recovery can produce ASTs where variadic parameters appear before
non-variadic ones (e.g. def foo(**kwargs, a):).
Trait Implementations§
Source§impl Clone for Parameters
impl Clone for Parameters
Source§fn clone(&self) -> Parameters
fn clone(&self) -> Parameters
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Parameters
impl Debug for Parameters
Source§impl Default for Parameters
impl Default for Parameters
Source§fn default() -> Parameters
fn default() -> Parameters
Source§impl<'a> From<&'a Parameters> for AnyNodeRef<'a>
impl<'a> From<&'a Parameters> for AnyNodeRef<'a>
Source§fn from(node: &'a Parameters) -> AnyNodeRef<'a>
fn from(node: &'a Parameters) -> AnyNodeRef<'a>
Source§impl<'a> From<&'a Parameters> for AnyRootNodeRef<'a>
impl<'a> From<&'a Parameters> for AnyRootNodeRef<'a>
Source§fn from(node: &'a Parameters) -> AnyRootNodeRef<'a>
fn from(node: &'a Parameters) -> AnyRootNodeRef<'a>
Source§impl<'a> From<&'a Parameters> for ComparableParameters<'a>
impl<'a> From<&'a Parameters> for ComparableParameters<'a>
Source§fn from(parameters: &'a Parameters) -> ComparableParameters<'a>
fn from(parameters: &'a Parameters) -> ComparableParameters<'a>
Source§impl GetSize for Parameters
impl GetSize for Parameters
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§fn get_heap_size_with_tracker<TRACKER>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)where
TRACKER: GetSizeTracker,
fn get_heap_size_with_tracker<TRACKER>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)where
TRACKER: GetSizeTracker,
tracker. Read moreSource§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Source§fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
tracker. Read moreSource§impl HasNodeIndex for Parameters
impl HasNodeIndex for Parameters
Source§fn node_index(&self) -> &AtomicNodeIndex
fn node_index(&self) -> &AtomicNodeIndex
AtomicNodeIndex for this node.Source§impl<'a> IntoIterator for &'a Box<Parameters>
impl<'a> IntoIterator for &'a Box<Parameters>
Source§type IntoIter = ParametersIterator<'a>
type IntoIter = ParametersIterator<'a>
Source§type Item = AnyParameterRef<'a>
type Item = AnyParameterRef<'a>
Source§fn into_iter(self) -> <&'a Box<Parameters> as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a Box<Parameters> as IntoIterator>::IntoIter
Source§impl<'a> IntoIterator for &'a Parameters
impl<'a> IntoIterator for &'a Parameters
Source§type IntoIter = ParametersIterator<'a>
type IntoIter = ParametersIterator<'a>
Source§type Item = AnyParameterRef<'a>
type Item = AnyParameterRef<'a>
Source§fn into_iter(self) -> <&'a Parameters as IntoIterator>::IntoIter
fn into_iter(self) -> <&'a Parameters as IntoIterator>::IntoIter
Source§impl PartialEq for Parameters
impl PartialEq for Parameters
Source§impl Ranged for Parameters
impl Ranged for Parameters
Source§impl<'a> TryFrom<AnyRootNodeRef<'a>> for &'a Parameters
impl<'a> TryFrom<AnyRootNodeRef<'a>> for &'a Parameters
impl StructuralPartialEq for Parameters
Auto Trait Implementations§
impl !Freeze for Parameters
impl RefUnwindSafe for Parameters
impl Send for Parameters
impl Sync for Parameters
impl Unpin for Parameters
impl UnsafeUnpin for Parameters
impl UnwindSafe for Parameters
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