Skip to content

Comments

[ty] do nothing with store_expression_type if inner_expression_inference_state is Get#21718

Merged
carljm merged 2 commits intoastral-sh:mainfrom
mtshiba:fix-1688
Dec 5, 2025
Merged

[ty] do nothing with store_expression_type if inner_expression_inference_state is Get#21718
carljm merged 2 commits intoastral-sh:mainfrom
mtshiba:fix-1688

Conversation

@mtshiba
Copy link
Collaborator

@mtshiba mtshiba commented Dec 1, 2025

Summary

Fixes astral-sh/ty#1688

Test Plan

N/A

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 1, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 1, 2025

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
+ src/scikit_build_core/_logging.py:153:13: warning[unsupported-base] Unsupported class base with type `<class 'Mapping[str, Style]'> | <class 'Mapping[str, Divergent]'>`
- Found 41 diagnostics
+ Found 42 diagnostics

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/_typing.pyi:1207:16: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 5806 diagnostics
+ Found 5807 diagnostics

No memory usage changes detected ✅

fn store_expression_type(&mut self, expression: &ast::Expr, ty: Type<'db>) {
if self.deferred_state.in_string_annotation() {
if self.deferred_state.in_string_annotation()
|| self.inner_expression_inference_state.is_get()
Copy link
Member

Choose a reason for hiding this comment

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

Could we use multi_inference_state::Ignore instead of having two modes that represent "read-only" type inference?

Copy link
Contributor

Choose a reason for hiding this comment

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

drive-by context: I am likely to modify this check for in_string_annotation to do the "store (Expr, Expr) for string annotation types" thing we've been discussing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could we use multi_inference_state::Ignore instead of having two modes that represent "read-only" type inference?

I understand that MultiInferenceState::Ignore is an option to perform the same calculation twice and discard the second result.
Since all type inference for expressions is skipped while in InnerExpressionInferenceState::Get, I think it should be used whenever possible (for example, when only diagnostics are needed, such as the handling in infer_subscript_type_expression for union types).
But I'm not sure whether this can be assumed in all cases where MultiInferenceState::Ignore is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is necessary for MultiInferenceState to redo inference, since it is doing it with different type context. So I think we need both.

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Dec 1, 2025
@mtshiba mtshiba marked this pull request as ready for review December 4, 2025 10:19
@AlexWaygood AlexWaygood removed their request for review December 4, 2025 11:12
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

This looks correct, thank you.

@carljm carljm merged commit 3511b7a into astral-sh:main Dec 5, 2025
42 checks passed
@mtshiba mtshiba deleted the fix-1688 branch December 5, 2025 02:07
dcreager added a commit that referenced this pull request Dec 5, 2025
* origin/main: (41 commits)
  [ty] Carry generic context through when converting class into `Callable` (#21798)
  [ty] Add more tests for renamings (#21810)
  [ty] Minor improvements to `assert_type` diagnostics (#21811)
  [ty] Add some attribute/method renaming test cases (#21809)
  Update mkdocs-material to 9.7.0 (Insiders now free) (#21797)
  Remove unused whitespaces in test cases (#21806)
  [ty] fix panic when instantiating a type variable with invalid constraints (#21663)
  [ty] fix build failure caused by conflicts between #21683 and #21800 (#21802)
  [ty] do nothing with `store_expression_type` if `inner_expression_inference_state` is `Get` (#21718)
  [ty] increase the limit on the number of elements in a non-recursively defined literal union (#21683)
  [ty] normalize typevar bounds/constraints in cycles (#21800)
  [ty] Update completion eval to include modules
  [ty] Add modules to auto-import
  [ty] Add support for module-only import requests
  [ty] Refactor auto-import symbol info
  [ty] Clarify the use of `SymbolKind` in auto-import
  [ty] Redact ranking of completions from e2e LSP tests
  [ty] Tweaks tests to use clearer language
  [ty] Update evaluation results
  [ty] Make auto-import ignore symbols in modules starting with a `_`
  ...
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: assertion left == right failed

5 participants