`bad-argument-type` in synthesized __init__ for a descriptor-typed field on a pydantic BaseModel with a @dataclass_transform metaclass (regression in 1.5.0)

オープン
#5,714 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python, rust
領域
devtools

調査の方向性

Reproduce with the two snippets in the issue: run pyrefly 1.5.0 on the Pydantic variant and confirm bad-argument-type for x, then compare against 1.4.1 to narrow the regression. The relevant area is synthesized __init__ generation for @dataclass_transform classes and how descriptor __set__ value types are read when a Pydantic ModelMetaclass is involved. Add a regression test covering the Pydantic metaclass plus descriptor field, and check the non-Pydantic case still infers int; done when both snippets type-check and the test suite passes.

索引モデルが issue の本文から書いたものです。

説明

pydantic
Describe the Bug

I've run into some typing errors with pyrefly 1.5.0 that didn't come up on 1.4.1 in the context of the Dagster framework's configurable resources. It doesn't seem to be specific to Dagster, and can be reproduced with Pydantic BaseModel classes. I'm currently using Python 3.14.10 with these pydantic packages installed in a Pixi + conda-forge managed environment:

pixi list | grep pydantic
Installed for: osx-arm64
pydantic                            2.14.4           pyh5ded981_0
pydantic-core                       2.50.5           py314h50bbb68_0
pydantic-extra-types                2.11.1           pyhcf101f3_0
pydantic-settings                   2.16.3           pyh5ded981_0

The result is a number of failures in our dagster project where we define a number of ConfigurableResource classes with dg.ResourceDependency[T] fields.

Minimal reproducers below generated using Claude, demonstrating behavior of similar metaclasses both with and without Pydantic

No Error Without Pydantic

from typing import Any, Generic, TypeVar, dataclass_transform

T = TypeVar("T")


class Dep(Generic[T]):
    def __get__(self, obj: Any, owner: Any) -> T:
        raise NotImplementedError

    def __set__(self, obj: object | None, value: T) -> None: ...


@dataclass_transform(kw_only_default=True)
class Meta(type): ...


class Base(metaclass=Meta): ...


class M(Base):
    x: Dep[int]


M(x=1)  # OK: __init__ takes the __set__ value type (int)

Error with Pydantic (on pyrefly 1.5.0)

from typing import Any, Generic, TypeVar, dataclass_transform

from pydantic import BaseModel, Field
from pydantic.main import ModelMetaclass

T = TypeVar("T")


class Dep(Generic[T]):
    """Stand-in for dagster.ResourceDependency[T]."""

    def __get__(self, obj: Any, owner: Any) -> T:
        raise NotImplementedError

    def __set__(self, obj: object | None, value: T) -> None: ...


@dataclass_transform(kw_only_default=True, field_specifiers=(Field,))
class Meta(ModelMetaclass): ...     # mirrors dagster's BaseConfigMeta


class Base(BaseModel, metaclass=Meta): ...


class M(Base):
    x: Dep[int]


M(x=1)   # 1.4.1: OK    1.5.0: bad-argument-type, parameter `x` has type `Dep[Unknown]`
Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

主要言語
Rust
スター
7.2k
フォーク
578
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

facebook/pyrefly のほかの issue

facebook/pyrefly の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。