[ty] Use key and value parameter types as type context for __setitem__ dunder calls (#22148)
## Summary Resolves https://github.com/astral-sh/ty/issues/2136.
This commit is contained in:
@@ -28,7 +28,6 @@ bitflags = { workspace = true }
|
||||
compact_str = { workspace = true }
|
||||
get-size2 = { workspace = true, optional = true }
|
||||
is-macro = { workspace = true }
|
||||
itertools = { workspace = true }
|
||||
memchr = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
salsa = { workspace = true, optional = true }
|
||||
|
||||
@@ -14,7 +14,6 @@ use std::slice::{Iter, IterMut};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use bitflags::bitflags;
|
||||
use itertools::Itertools;
|
||||
|
||||
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||
|
||||
@@ -3380,10 +3379,13 @@ impl Arguments {
|
||||
/// 2
|
||||
/// {'4': 5}
|
||||
/// ```
|
||||
pub fn arguments_source_order(&self) -> impl Iterator<Item = ArgOrKeyword<'_>> {
|
||||
let args = self.args.iter().map(ArgOrKeyword::Arg);
|
||||
let keywords = self.keywords.iter().map(ArgOrKeyword::Keyword);
|
||||
args.merge_by(keywords, |left, right| left.start() <= right.start())
|
||||
pub fn arguments_source_order(&self) -> ArgumentsSourceOrder<'_> {
|
||||
ArgumentsSourceOrder {
|
||||
args: &self.args,
|
||||
keywords: &self.keywords,
|
||||
next_arg: 0,
|
||||
next_keyword: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inner_range(&self) -> TextRange {
|
||||
@@ -3399,6 +3401,38 @@ impl Arguments {
|
||||
}
|
||||
}
|
||||
|
||||
/// The iterator returned by [`Arguments::arguments_source_order`].
|
||||
#[derive(Clone)]
|
||||
pub struct ArgumentsSourceOrder<'a> {
|
||||
args: &'a [Expr],
|
||||
keywords: &'a [Keyword],
|
||||
next_arg: usize,
|
||||
next_keyword: usize,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for ArgumentsSourceOrder<'a> {
|
||||
type Item = ArgOrKeyword<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let arg = self.args.get(self.next_arg);
|
||||
let keyword = self.keywords.get(self.next_keyword);
|
||||
|
||||
if let Some(arg) = arg
|
||||
&& keyword.is_none_or(|keyword| arg.start() <= keyword.start())
|
||||
{
|
||||
self.next_arg += 1;
|
||||
Some(ArgOrKeyword::Arg(arg))
|
||||
} else if let Some(keyword) = keyword {
|
||||
self.next_keyword += 1;
|
||||
Some(ArgOrKeyword::Keyword(keyword))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FusedIterator for ArgumentsSourceOrder<'_> {}
|
||||
|
||||
/// An AST node used to represent a sequence of type parameters.
|
||||
///
|
||||
/// For example, given:
|
||||
|
||||
Reference in New Issue
Block a user