mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[red-knot] Fix panic for tuple[x[y]]
string annotation (#17787)
## Summary closes #17775 ## Test Plan Added corpus regression test
This commit is contained in:
parent
3cf44e401a
commit
6d2c10cca2
4 changed files with 20 additions and 14 deletions
|
@ -0,0 +1 @@
|
|||
t: "tuple[list[int]]"
|
|
@ -1,35 +1,30 @@
|
|||
Expression # cycle panic (signature_)
|
||||
Tanjun # cycle panic (signature_)
|
||||
aiohttp # missing expression ID
|
||||
alerta # missing expression ID
|
||||
altair # cycle panics (try_metaclass_)
|
||||
antidote # hangs / slow
|
||||
artigraph # cycle panics (value_type_)
|
||||
colour # cycle panics (try_metaclass_)
|
||||
core # cycle panics (value_type_)
|
||||
cpython # missing expression ID, access to field whilst being initialized, too many cycle iterations
|
||||
cpython # access to field whilst being initialized, too many cycle iterations
|
||||
discord.py # some kind of hang, only when multi-threaded?
|
||||
freqtrade # cycle panics (try_metaclass_)
|
||||
hydpy # cycle panics (try_metaclass_)
|
||||
ibis # cycle panics (try_metaclass_)
|
||||
manticore # stack overflow
|
||||
materialize # stack overflow
|
||||
meson # missing expression ID
|
||||
mypy # cycle panic (signature_)
|
||||
pandas # slow
|
||||
pandas-stubs # cycle panics (try_metaclass_)
|
||||
pandera # cycle panics (try_metaclass_)
|
||||
prefect # slow
|
||||
pytest # cycle panics (signature_), missing expression ID
|
||||
pytest # cycle panics (signature_)
|
||||
pywin32 # bad use-def map (binding with definitely-visible unbound)
|
||||
schemathesis # cycle panics (signature_)
|
||||
scikit-learn # success, but mypy-primer hangs processing the output
|
||||
scipy # missing expression ID
|
||||
scipy # missing expression type ("expression should belong to this TypeInference region")
|
||||
spack # success, but mypy-primer hangs processing the output
|
||||
spark # cycle panics (try_metaclass_)
|
||||
sphinx # missing expression ID
|
||||
steam.py # missing expression ID
|
||||
steam.py # cycle panics (try_metaclass_), often hangs when multi-threaded
|
||||
streamlit # cycle panic (signature_)
|
||||
sympy # stack overflow
|
||||
trio # missing expression ID
|
||||
xarray # cycle panics (try_metaclass_)
|
||||
|
|
|
@ -2,10 +2,12 @@ AutoSplit
|
|||
PyGithub
|
||||
PyWinCtl
|
||||
SinbadCogs
|
||||
aiohttp
|
||||
aiohttp-devtools
|
||||
aioredis
|
||||
aiortc
|
||||
alectryon
|
||||
alerta
|
||||
anyio
|
||||
apprise
|
||||
arviz
|
||||
|
@ -47,6 +49,7 @@ jinja
|
|||
koda-validate
|
||||
kopf
|
||||
kornia
|
||||
meson
|
||||
mitmproxy
|
||||
mkdocs
|
||||
mkosi
|
||||
|
@ -92,11 +95,13 @@ scrapy
|
|||
setuptools
|
||||
sockeye
|
||||
speedrun.com_global_scoreboard_webapp
|
||||
sphinx
|
||||
starlette
|
||||
static-frame
|
||||
stone
|
||||
strawberry
|
||||
tornado
|
||||
trio
|
||||
twine
|
||||
typeshed-stats
|
||||
urllib3
|
||||
|
|
|
@ -7615,7 +7615,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
fn element_could_alter_type_of_whole_tuple(
|
||||
element: &ast::Expr,
|
||||
element_ty: Type,
|
||||
builder: &TypeInferenceBuilder,
|
||||
builder: &mut TypeInferenceBuilder,
|
||||
) -> bool {
|
||||
if !element_ty.is_todo() {
|
||||
return false;
|
||||
|
@ -7624,10 +7624,15 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
match element {
|
||||
ast::Expr::EllipsisLiteral(_) | ast::Expr::Starred(_) => true,
|
||||
ast::Expr::Subscript(ast::ExprSubscript { value, .. }) => {
|
||||
matches!(
|
||||
builder.expression_type(value),
|
||||
Type::KnownInstance(KnownInstanceType::Unpack)
|
||||
)
|
||||
let value_ty = if builder.deferred_state.in_string_annotation() {
|
||||
// Using `.expression_type` does not work in string annotations, because
|
||||
// we do not store types for sub-expressions. Re-infer the type here.
|
||||
builder.infer_expression(value)
|
||||
} else {
|
||||
builder.expression_type(value)
|
||||
};
|
||||
|
||||
matches!(value_ty, Type::KnownInstance(KnownInstanceType::Unpack))
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue