False `bad-override` on SQLModel `__tablename__ = "..."` ("must both be descriptors")
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Rust
- Stelle
- 7.2k
- Fork
- 578
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di facebook/pyrefly
-
pytorch tensor-shapes typechecking
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
good first issue typechecking
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
cargo b warning: unused dependency `zstd`Forse già presa @Narendersingh007 l’ha presa 4 giorni fa. Apertagood first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
-
pydantic
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Tutte le issue di facebook/pyrefly
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
eventflux-io/eventflux#203 ·
I maintainer di solito rispondono entro 1 giorno
-
bug ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
userFRM/egui-charts#4068 ·
I maintainer di solito rispondono entro 1 giorno
-
fuzz-crash review-followup
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 Mezza giornata Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
aws/aws-emulator#610 ·