`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)

Aperta
#5,714 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python, rust
Ambito
devtools

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Rust
Stelle
7.2k
Fork
578
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di facebook/pyrefly

Tutte le issue di facebook/pyrefly

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.