Skip to content

Fix cls diagnostic wording and quoted type[] hover - #4723

Closed
Divyansh151005 wants to merge 1 commit into
facebook:mainfrom
Divyansh151005:fix/cls-diagnostic-and-quoted-type-hover
Closed

Divyansh151005 wants to merge 1 commit into
facebook:mainfrom
Divyansh151005:fix/cls-diagnostic-and-quoted-type-hover

Conversation

@Divyansh151005

@Divyansh151005 Divyansh151005 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes two presentation issues from #4703:

  1. invalid-annotation for cls/self receivers — compare class to class (Child is not a superclass of class Base) instead of mixing a class-object type with a class name (type[Child] … superclass of class Base).
  2. Hover on quoted names inside type['Child'] — prefer type traces at the string content range (where rewritten forward-ref Name nodes are recorded) so hover shows type[Child] like an unquoted type[Child], not type[type[Child]] from the enclosing type[...] expression.

Also avoids double-rendering Type::Type(ClassDef(_)) in the display layer, since ClassDef already prints as type[C].

Fixes #4703

Test Plan

$ export CARGO_TARGET_DIR=/Users/divyanshbarodiya/Desktop/pyrefly-cargo-target
$ cargo test -p pyrefly --lib quoted_class_in_type_subscript_hover
test test::lsp::hover_type::quoted_class_in_type_subscript_hover ... ok

$ cargo test -p pyrefly --lib classmethod_subclass_cls_diagnostic_wording
test test::typing_self::test_classmethod_subclass_cls_diagnostic_wording ... ok
# emits: `method`: `Child` is not a superclass of class `Base`

$ cargo test -p pyrefly --lib bad_receiver_annotation
test result: ok. 2 passed; 0 failed

$ cargo test -p pyrefly --lib 'test::constructors::'
test result: ok. 88 passed; 0 failed

$ cargo test -p pyrefly --lib 'test::typing_self::'
test result: ok. 48 passed; 0 failed

$ cargo test -p pyrefly --lib 'test::lsp::hover_type::'
test result: ok. 23 passed; 0 failed

$ python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema
Finished successfully

Reject self/cls superclass diagnostics by comparing class to class
(e.g. `Child` vs `Base`) instead of mixing `type[Child]` with class
`Base`. For hover, prefer type traces at string content ranges so a
quoted name inside `type['Child']` resolves like an unquoted `Child`
instead of the enclosing `type[...]` expression.

Co-authored-by: Cursor <cursoragent@cursor.com>
@meta-codesync

meta-codesync Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D117995447. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity for more than 2 weeks.

If you are still working on this this pull request, please add a comment or push new commits to keep it active. Otherwise, please unassign yourself and allow someone else to take over.

Thank you for your contributions!

@github-actions github-actions Bot added the stale label Sep 14, 2026

@rchen152 rchen152 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! I'll merge this after getting a second internal review.

FYI I patched one minor issue, which is that the hover logic needs to find the part of the expression that is being hovered over rather than using the entire expression. (No action needed from you.)

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in 3db5f14 Oct 9, 2026
@meta-codesync

meta-codesync Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@rchen152 merged this pull request in 3db5f14.

@meta-codesync meta-codesync Bot added the Merged label Oct 9, 2026
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.

Class-object types are rendered inconsistently in cls diagnostics and quoted-annotation hovers

4 participants