Skip to content

[ty] Move 'scipy' to list of 'good' projects#17850

Merged
sharkdp merged 2 commits into
mainfrom
david/fix-17792-update-project-list
May 5, 2025
Merged

[ty] Move 'scipy' to list of 'good' projects#17850
sharkdp merged 2 commits into
mainfrom
david/fix-17792-update-project-list

Conversation

@sharkdp

@sharkdp sharkdp commented May 5, 2025

Copy link
Copy Markdown
Contributor

Summary

Adds scipy as a new project to good.txt as a follow-up to #17849.

@sharkdp sharkdp added the ty Multi-file analysis & type inference label May 5, 2025
@github-actions

github-actions Bot commented May 5, 2025

Copy link
Copy Markdown
Contributor

mypy_primer results

No ecosystem changes detected ✅

@sharkdp sharkdp force-pushed the david/fix-17792 branch from 3f16a5e to 393b847 Compare May 5, 2025 11:18
@sharkdp sharkdp force-pushed the david/fix-17792-update-project-list branch from c7b0814 to 01b7193 Compare May 5, 2025 11:19
@sharkdp sharkdp marked this pull request as ready for review May 5, 2025 11:37
Base automatically changed from david/fix-17792 to main May 5, 2025 11:52
sharkdp added a commit that referenced this pull request May 5, 2025
…17849)

## Summary

When entering an `infer_expression_types` cycle from
`TypeInferenceBuilder::infer_standalone_expression`, we might get back a
`TypeInference::cycle_fallback(…)` that doesn't actually contain any new
types, but instead it contains a `cycle_fallback_type` which is set to
`Some(Type::Never)`. When calling `self.extend(…)`, we therefore don't
really pull in a type for the expression we're interested in. This
caused us to panic if we tried to call `self.expression_type(…)` after
`self.extend(…)`.

The proposed fix here is to retrieve that type from the nested
`TypeInferenceBuilder` directly, which will correctly fall back to
`cycle_fallback_type`.

## Details

I minimized the second example from #17792 a bit further and used this
example for debugging:

```py
from __future__ import annotations

class C: ...

def f(arg: C):
    pass

x, _ = f(1)

assert x
```

This is self-referential because when we check the assignment statement
`x, _ = f(1)`, we need to look up the signature of `f`. Since evaluation
of annotations is deferred, we look up the public type of `C` for the
`arg` parameter. The public use of `C` is visibility-constraint by "`x`"
via the `assert` statement. While evaluating this constraint, we need to
look up the type of `x`, which in turn leads us back to the `x, _ =
f(1)` definition.

The reason why this only showed up in the relatively peculiar case with
unpack assignments is the code here:


https://github.com/astral-sh/ruff/blob/78b4c3ccf1d6cb10613671ccec09cafba0d1de72/crates/ty_python_semantic/src/types/infer.rs#L2709-L2718

For a non-unpack assignment like `x = f(1)`, we would not try to infer
the right-hand side eagerly. Instead, we would enter a
`infer_definition_types` cycle that handles the situation correctly. For
unpack assignments, however, we try to infer the type of `value`
(`f(1)`) and therefore enter the cycle via `standalone_expression_type
=> infer_expression_type`.

closes #17792 

## Test Plan

* New regression test
* Made sure that we can now run successfully on scipy => see #17850
@sharkdp sharkdp requested a review from MichaReiser as a code owner May 5, 2025 11:52
@sharkdp sharkdp merged commit 5a91bad into main May 5, 2025
35 checks passed
@sharkdp sharkdp deleted the david/fix-17792-update-project-list branch May 5, 2025 11:52
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request May 6, 2025
…stral-sh#17849)

## Summary

When entering an `infer_expression_types` cycle from
`TypeInferenceBuilder::infer_standalone_expression`, we might get back a
`TypeInference::cycle_fallback(…)` that doesn't actually contain any new
types, but instead it contains a `cycle_fallback_type` which is set to
`Some(Type::Never)`. When calling `self.extend(…)`, we therefore don't
really pull in a type for the expression we're interested in. This
caused us to panic if we tried to call `self.expression_type(…)` after
`self.extend(…)`.

The proposed fix here is to retrieve that type from the nested
`TypeInferenceBuilder` directly, which will correctly fall back to
`cycle_fallback_type`.

## Details

I minimized the second example from astral-sh#17792 a bit further and used this
example for debugging:

```py
from __future__ import annotations

class C: ...

def f(arg: C):
    pass

x, _ = f(1)

assert x
```

This is self-referential because when we check the assignment statement
`x, _ = f(1)`, we need to look up the signature of `f`. Since evaluation
of annotations is deferred, we look up the public type of `C` for the
`arg` parameter. The public use of `C` is visibility-constraint by "`x`"
via the `assert` statement. While evaluating this constraint, we need to
look up the type of `x`, which in turn leads us back to the `x, _ =
f(1)` definition.

The reason why this only showed up in the relatively peculiar case with
unpack assignments is the code here:


https://github.com/astral-sh/ruff/blob/78b4c3ccf1d6cb10613671ccec09cafba0d1de72/crates/ty_python_semantic/src/types/infer.rs#L2709-L2718

For a non-unpack assignment like `x = f(1)`, we would not try to infer
the right-hand side eagerly. Instead, we would enter a
`infer_definition_types` cycle that handles the situation correctly. For
unpack assignments, however, we try to infer the type of `value`
(`f(1)`) and therefore enter the cycle via `standalone_expression_type
=> infer_expression_type`.

closes astral-sh#17792 

## Test Plan

* New regression test
* Made sure that we can now run successfully on scipy => see astral-sh#17850
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request May 6, 2025
## Summary

Adds `scipy` as a new project to `good.txt` as a follow-up to astral-sh#17849.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant