Descriptor override of an `Any` attribute is rejected with decorator syntax but accepted with explicit assignment

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

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

評価

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

調査の方向性

Start by tracing the class member override checks that produce the bad-override diagnostic, then compare how decorator syntax and explicit assignment represent descriptor values. Use the supplied sandbox example to reproduce the discrepancy and look for nearby tests covering inherited Any attributes and descriptors. Done means both forms are accepted consistently, with the relevant regression test passing.

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

説明

sqlalchemy
Describe the Bug
class Descriptor:
    def __init__(self, *_: object) -> None:
        pass

    def __get__(self, *_: object) -> int:
        return 1

    def __set__(self, *_: Any) -> None:
        pass


class Base:
    x: Any


class Assigned(Base):
    x: Descriptor = Descriptor(lambda cls: 1)  # Accepted


class Decorated(Base):
    @Descriptor
    def x(cls) -> int:  # Rejected
        return 1

Specifically, the error is:

ERROR Class member `Decorated.x` overrides parent class `Base` in an inconsistent manner [bad-override]
  `Decorated.x` and `Base.x` must both be descriptors

I'd expect both forms to be accepted: they both create an instance of the same descriptor class. Using decorator syntax shouldn't change whether it can override the inherited Any attribute.

For context, we're currently migrating from Pyright to Pyrefly and this issue is the largest cause of errors, specifically, we're using a SQLAlchemy construction:

@declared_attr.directive
@classmethod
def __table_args__(cls) -> Any:
  ...
Sandbox Link

Sandbox

(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 を短くまとめたダイジェスト。