Skip to content

Conversation

@pareshjoshij
Copy link
Contributor

@pareshjoshij pareshjoshij commented Dec 2, 2025

Closes #724

Summary
This PR adds precise type annotations for the return value of np.einsum_path.

Changes

  • Updated _OptimizeKind to include Sequence[str | tuple[int, ...]].
  • Updated einsum_path return type to tuple[list[str | tuple[int, ...]], str].
  • Added a static regression test case in src/numpy-stubs/@test/static/accept/test_einsum_path.py.

Verification
I verified the changes statically with mypy and confirmed the runtime behavior matches the new annotation.

1. Static Check (Mypy)

Success: no issues found in 1 source file
Capture

@jorenham jorenham changed the title MAINT: Annotate np.einsum_path return type (Issue #724) TYP: Annotate einsum_path return type (Issue #724) Dec 2, 2025
@pareshjoshij
Copy link
Contributor Author

@jorenham sir I tried running this locally and got results with different lengths like (0,) for size 1 and others for size 2). I used ... to be safe since it seems variable, but please let me know if there's a better way to handle that.

Also, I noticed the CLI checks failed on the existing tests—should I just update those files to match this new type?

@jorenham
Copy link
Member

jorenham commented Dec 2, 2025

I tried running this locally and got results with different lengths like (0,) for size 1 and others for size 2). I used ... to be safe since it seems variable, but please let me know if there's a better way to handle that.

Ah I see... It's a bit unfortunate, but nothing to lose sleep over 🤷. Anyway, tuple[int, ...] is then indeed the right way to go here

Also, I noticed the CLI checks failed on the existing tests—should I just update those files to match this new type?

Yea it's better to update those instead of writing new ones then.

@pareshjoshij pareshjoshij requested a review from jorenham December 2, 2025 12:05
Refactor assertion for np.einsum_path to improve readability.
@pareshjoshij
Copy link
Contributor Author

@jorenham sir Expert advice needed! 🏳️

The Linter and Formatter seem to be at war over these long lines. Every time I appease one, the other gets angry. 🤯

@jorenham
Copy link
Member

jorenham commented Dec 2, 2025

The Linter and Formatter seem to be at war over these long lines. Every time I appease one, the other gets angry. 🤯

Running uv run ruff check --fix could help

@pareshjoshij
Copy link
Contributor Author

The Linter and Formatter seem to be at war over these long lines. Every time I appease one, the other gets angry. 🤯

Running uv run ruff check --fix could help

Done

@jorenham jorenham changed the title TYP: Annotate einsum_path return type (Issue #724) 🏷️ Annotate einsum_path return type (Issue #724) Dec 2, 2025
@jorenham jorenham merged commit 2d9af3f into numpy:main Dec 2, 2025
21 checks passed
@jorenham
Copy link
Member

jorenham commented Dec 2, 2025

Thanks @pareshjoshij

@pareshjoshij pareshjoshij deleted the fix/einsum-path-annotation branch December 3, 2025 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

annotate np.einsum_path return type

2 participants