Skip to content

[ty] Refactor if narrowing #18392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ericmarkmartin
Copy link
Contributor

@ericmarkmartin ericmarkmartin commented May 30, 2025

Summary

Refactor the semantic index builder’s If statement analysis. This change also lets us detect more unreachable code paths.

Test Plan

  • Add new tests to unreachable.md
  • Update existing tests

@MichaReiser MichaReiser changed the title Refactor if narrowing [ty] Refactor if narrowing May 30, 2025
@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label May 30, 2025
@carljm
Copy link
Contributor

carljm commented May 30, 2025

Looks like there are still some failing tests here? Let me know if any of these are things you'd like a second pair of eyes on how to address; otherwise I'll mark this as draft, go ahead and put it back up for review when CI is green.

@carljm carljm marked this pull request as draft May 30, 2025 22:18
@ericmarkmartin
Copy link
Contributor Author

ericmarkmartin commented May 31, 2025

Looks like there are still some failing tests here? Let me know if any of these are things you'd like a second pair of eyes on how to address; otherwise I'll mark this as draft, go ahead and put it back up for review when CI is green.

Looks like we're green now, but mypy primer seems unhappy (sorry if that means I shouldn't have opened it, but I'm not sure how to proceed with primer failures)

@ericmarkmartin ericmarkmartin marked this pull request as ready for review May 31, 2025 21:40
@sharkdp
Copy link
Contributor

sharkdp commented Jun 4, 2025

Thank you for working on this!

Looks like we're green now, but mypy primer seems unhappy

The mypy_primer run was failing due to a network error. I re-ran it now and it fails with

fatal[panic] Panicked at crates/ty_python_semantic/src/symbol.rs:927:21 when checking `/tmp/mypy_primer/projects/trio/src/trio/_core/__init__.py`: `internal error: entered unreachable code: If we have at least one declaration, the scope-start should not be definitely visible`

This might be related to astral-sh/ty#365 (comment). I am planning to fix that bug as soon as #18041 is merged (which makes significant changes to the semantic index builder, and has a much higher impact). I suggest that we wait with this PR until these two things have been resolved.

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.

4 participants