Skip to content

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Aug 13, 2025

Summary

Various minor cleanups split out from #19877, which we decided not to go with:

  • Rename Tuple::from_elements() to Tuple::heterogeneous(). It better expresses what the method does to external callers.
  • Refactor TupleType::empty() and TupleType::homogeneous() to return TupleType<'db> rather than Option<TupleType<'db>>. They always return Some() on main, but this isn't currently expressed by the type signature. Refactoring them to return TupleType<'db> avoids the need for one .expect() call and one .unwrap() call.
  • Remove the complicated trait bounds from TupleType::new(). These were originally a performance optimisation, but we're no longer sure it buys us anything: see [ty] Move Salsa caching "down a layer" in tuple.rs #19877 (comment).
  • Move Type::homogeneous_tuple(), Type::empty_tuple() and Type::heterogeneous_tuple() from tuple.rs to instance.rs. The same functionality can be implemented with less indirection in that submodule, because we have access to the NominalInstanceType internals from that module.

Test Plan

Existing tests

@AlexWaygood AlexWaygood added internal An internal refactor or improvement ty Multi-file analysis & type inference labels Aug 13, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Aug 13, 2025

Diagnostic diff on typing conformance tests

Changes were detected when running ty on typing conformance tests
--- old-output.txt	2025-08-13 13:44:30.744994771 +0000
+++ new-output.txt	2025-08-13 13:44:30.811995136 +0000
@@ -1,5 +1,5 @@
 WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
-fatal[panic] Panicked at /home/runner/.cargo/git/checkouts/salsa-e6f3bb7c2a062968/918d35d/src/function/execute.rs:215:25 when checking `/home/runner/work/ruff/ruff/typing/conformance/tests/aliases_typealiastype.py`: `infer_definition_types(Id(3cd6)): execute: too many cycle iterations`
+fatal[panic] Panicked at /home/runner/.cargo/git/checkouts/salsa-e6f3bb7c2a062968/918d35d/src/function/execute.rs:215:25 when checking `/home/runner/work/ruff/ruff/typing/conformance/tests/aliases_typealiastype.py`: `infer_definition_types(Id(2cbf)): execute: too many cycle iterations`
 _directives_deprecated_library.py:15:31: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `int`
 _directives_deprecated_library.py:30:26: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `str`
 _directives_deprecated_library.py:36:41: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `Self@__add__`

@github-actions
Copy link
Contributor

github-actions bot commented Aug 13, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@AlexWaygood AlexWaygood marked this pull request as ready for review August 13, 2025 09:58
@AlexWaygood AlexWaygood enabled auto-merge (squash) August 13, 2025 13:43
@AlexWaygood AlexWaygood merged commit 5725c4b into main Aug 13, 2025
37 checks passed
@AlexWaygood AlexWaygood deleted the alex/tuple-cleanups branch August 13, 2025 13:46
dcreager added a commit that referenced this pull request Aug 13, 2025
* main:
  [ty] Add precise inference for indexing, slicing and unpacking `NamedTuple` instances (#19560)
  Add rule code to GitLab description (#19896)
  [ty] render docstrings in hover (#19882)
  [ty] simplify return type of place_from_declarations (#19884)
  [ty] Various minor cleanups to tuple internals (#19891)
  [ty] Improve `sys.version_info` special casing (#19894)
dcreager added a commit that referenced this pull request Aug 13, 2025
…aints

* dcreager/inferrable: (65 commits)
  this was right after all
  mark typevars inferrable as we go
  fix tests
  fix inference of constrained typevars
  [ty] Add precise inference for indexing, slicing and unpacking `NamedTuple` instances (#19560)
  Add rule code to GitLab description (#19896)
  [ty] render docstrings in hover (#19882)
  [ty] simplify return type of place_from_declarations (#19884)
  [ty] Various minor cleanups to tuple internals (#19891)
  [ty] Improve `sys.version_info` special casing (#19894)
  Don't cache files with diagnostics (#19869)
  [ty] support recursive type aliases (#19805)
  [ty] Remove unsafe `salsa::Update` implementations in `tuple.rs` (#19880)
  [ty] Function argument inlay hints (#19269)
  [ty] Remove Salsa interning for `TypedDictType` (#19879)
  Fix `lint.future-annotations` link (#19876)
  [ty] Reduce memory usage of `TupleSpec` and `TupleType` (#19872)
  [ty] Track heap usage of salsa structs (#19790)
  Update salsa to pull in tracked struct changes (#19843)
  [ty] simplify CycleDetector::visit signature (#19873)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants