False `bad-override` on SQLModel `__tablename__ = "..."` ("must both be descriptors")

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

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

評価

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

調査の方向性

Start by locating Pyrefly's bad-override diagnostic and the logic that compares class member descriptors; the issue does not name source files or tests. Reproduce with the shown SQLModel example using Python 3.13 and SQLModel 0.0.38, then check the existing override tests. Done when a plain string and a declared_attr directive override are accepted without regressing other override checks.

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

説明

question sqlalchemy
Describe the Bug

Setting __tablename__ to a string on a SQLModel table, which is how SQLModel's docs name a table, is reported as bad-override:

from sqlmodel import Field, SQLModel


class Hero(SQLModel, table=True):
    __tablename__ = "heroes"
    id: int | None = Field(default=None, primary_key=True)
ERROR Class member `Hero.__tablename__` overrides parent class `SQLModel` in an inconsistent manner [bad-override]
 --> repro.py:5:5
  `Hero.__tablename__` and `SQLModel.__tablename__` must both be descriptors

SQLModel declares __tablename__ as a @declared_attr classmethod-style descriptor, but SQLAlchemy and SQLModel both accept a plain string in a subclass at runtime. Writing the override as a descriptor does not help either:

from sqlalchemy.orm import declared_attr

class Hero(SQLModel, table=True):
    @declared_attr.directive
    def __tablename__(cls) -> str:
        return "heroes"

This still reports the same error, so there is no spelling that type-checks. In a codebase with many tables, the result is one error per model.

Expected: a plain str (or a declared_attr directive) is accepted as an override of declared_attr __tablename__. Possibly related: #891, #2561.

Versions: pyrefly 1.3.1, sqlmodel 0.0.38, SQLAlchemy 2.0.49, Python 3.13. The config is just python-version = "3.13" (default preset). The basic preset does not report it.

Sandbox Link

No response (needs sqlmodel installed)

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