Skip to content

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented May 26, 2025

Summary

fixes astral-sh/ty#366

Test Plan

  • Added panic corpus regression tests
  • I also wrote a hover regression test (see below), but decided not to include it. The corpus tests are much more "effective" at finding these types of errors, since they exhaustively check all expressions for types.
#[test]
fn hover_regression_test_366() {
    let test = cursor_test(
        r#"
    from ty_extensions import Intersection

    class A: ...
    class B: ...

    def _(x: Intersection[A,<CURSOR> B]):
        pass
    "#,
    );

    assert_snapshot!(test.hover(), @r"
    A & B
    ---------------------------------------------
    ```text
    A & B
    ```
    ---------------------------------------------
    info[hover]: Hovered content is
     --> main.py:7:31
      |
    5 |         class B: ...
    6 |
    7 |         def _(x: Intersection[A, B]):
      |                               ^^-^
      |                               | |
      |                               | Cursor offset
      |                               source
    8 |             pass
      |
    ");
}

@sharkdp sharkdp added the ty Multi-file analysis & type inference label May 26, 2025
@github-actions
Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅

pass


def _(x: Intersection[A], y: Intersection[A, B]):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The single-argument variant needs to be checked separately, as it takes a different code path. It's important not to store types for the single-argument variant, as that happens implicitly in the self.infer_type_expression(element) call a few lines above.

@sharkdp sharkdp merged commit 4e68dd9 into main May 26, 2025
35 checks passed
@sharkdp sharkdp deleted the david/fix-366 branch May 26, 2025 15:08
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.

panic: expression should belong to this TypeInference region and TypeInferenceBuilder should have inferred a type for it

3 participants