Skip to content

[ty] Return getter and setter definitions for properties#24349

Closed
mvanhorn wants to merge 1 commit intoastral-sh:mainfrom
mvanhorn:fix/definitions-for-attribute-getter-setter
Closed

[ty] Return getter and setter definitions for properties#24349
mvanhorn wants to merge 1 commit intoastral-sh:mainfrom
mvanhorn:fix/definitions-for-attribute-getter-setter

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Apr 1, 2026

Summary

Follow-up to #24065 as discussed with @MichaReiser. definitions_for_attribute_in_class_hierarchy now returns both getter and setter definitions for properties instead of stopping at the first match.

Problem

The function used break 'scopes after finding the first definition within a class scope's declarations or bindings. For a property with both @property getter and @prop.setter, only the getter was returned. This meant:

  • Go-to-definition showed only the getter, not both getter and setter
  • The readonly classification relied on the type system rather than definition-level information

Fix

Instead of breaking immediately on the first definition found, collect all definitions from the same scope (declarations or bindings) before breaking to the next ancestor. The break 'scopes now fires after the scope is fully scanned, preserving the MRO traversal behavior while returning complete definition sets.

Test plan

  • property_readonly_modifier test passes (verifies getter-only = readonly, getter+setter = not readonly)
  • All 77 semantic_tokens tests pass
  • All 224 goto tests pass
  • All 25 ide_support tests pass
  • Clippy clean, uvx prek run -a clean

This contribution was developed with AI assistance (Claude Code).

Previously, `definitions_for_attribute_in_class_hierarchy` used
`break 'scopes` after finding the first definition within a class
scope. For properties with both a getter and setter, this returned
only the getter definition, causing go-to-definition to show only
the getter and preventing correct readonly classification when the
setter exists in a different binding.

Now the function collects all declarations/bindings from the same
scope before breaking, so property getter+setter pairs are both
returned. This matches Pylance's behavior as suggested in astral-sh#24065.
@astral-sh-bot astral-sh-bot bot added the ty Multi-file analysis & type inference label Apr 1, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Apr 1, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 86.76%. The percentage of expected errors that received a diagnostic held steady at 81.53%. The number of fully passing files held steady at 70/132.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Apr 1, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Apr 1, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@MichaReiser
Copy link
Copy Markdown
Member

Thanks, and sorry for not mentioning this in your PR but I went ahead and implemented this myself #24332

@MichaReiser MichaReiser closed this Apr 2, 2026
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.

3 participants