Skip to content

fix default value become ... in hover a sqlalchemy orm class #4802 - #5723

Closed
asukaminato0721 wants to merge 2 commits into
pyrefly-org:mainfrom
asukaminato0721:4802
Closed

asukaminato0721 wants to merge 2 commits into
pyrefly-org:mainfrom
asukaminato0721:4802

Conversation

@asukaminato0721

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4802

SQLAlchemy, attrs constructor hovers now show explicit defaults, including None.

  • I am a human, and I fully understand the code I am submitting.

Test Plan

@meta-cla meta-cla Bot added the cla signed label Nov 22, 2026
@asukaminato0721 asukaminato0721 changed the title 4802 fix default value become ... in hover a sqlalchemy orm class #4802 Nov 22, 2026
@meta-codesync

meta-codesync Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@github-actions
github-actions Bot requested a review from samwgoldman November 23, 2026 09:08
@rchen152 rchen152 assigned rchen152 and unassigned samwgoldman Nov 24, 2026
@rchen152
rchen152 requested review from rchen152 and removed request for samwgoldman November 24, 2026 01:01

@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.

Thanks!

It looks like there's one issue we need to fix before we merge, we're creating too many Unknown types (which probably explains the noisy mypy primer result).

AI reviewer notes here:

Do not turn synthetic defaults into unknown constructor types

At pyrefly/lib/alt/class/dataclass.rs:1369–1370, every existing field-default payload is now attached to the generated parameter:

Required::Optional(field_flags.default.clone())

But an ordinary annotated class-body default is represented upstream by a placeholder implicit Any, not its actual value. Wrapping that placeholder in DefaultValue does not make it a real value. DefaultValue’s visitor delegates to ty, so signature unknownness checks now encounter it.

Minimal counterexample:

from dataclasses import dataclass
from typing import Callable

@dataclass
class C:
    value: int = 0

init: Callable[[C, int], None] = C.__init__

Check with pyrefly check --preset all:

  • Base: no partially-unknown-type error.
  • Head: The type of attribute __init__ is partially unknown; it contains an implicit Any.
  • mypy --strict: accepts the equivalent reproducer.
  • Runtime: constructor/default behavior is ordinary and valid.

Violated contract: the generated constructor’s annotated parameter and return types are fully known. A sentinel recording “this field has a default” is not an unknown input annotation. The PR’s display improvement should not create an unknown type in that signature.

Impact: valid, fully annotated dataclass constructor references gain false diagnostics under all. The primer’s large partially-unknown cluster is consistent with this path, including ordinary-default dataclasses in Meson. This is not a complaint about all being strict: the unknownness is introduced by the checker itself.

Why fix here: this is a direct regression caused by the new payload propagation, on a common construct. Documenting it or disabling the diagnostic would not repair the representation/consumer boundary. Do not attach the existing placeholder Any as a genuine callable default. Preserve default display while keeping synthetic optionality markers out of signature unknownness, and rerun the primer after correction.

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@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 78a9517 Nov 24, 2026
@meta-codesync meta-codesync Bot added the Merged label Nov 24, 2026
@meta-codesync

meta-codesync Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 78a9517.

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.

default value become ... in hover a sqlalchemy orm class

4 participants