Pyright cannot recognize the type of `SQLModel.__tablename__`

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from sqlmodel import SQLModel

reveal_type(SQLModel.__tablename__)

# mypy(0.910) output: Revealed type is "Union[builtins.str, def (*Any, **Any) -> builtins.str]"
# pyright(1.1.166) output: Type of "SQLModel.__tablename__" is "declared_attr"


class User(SQLModel, table=True):  # pyright error: Instance variable "__name__" overrides class variable of same name in class "SQLModel"
    __tablename__ = "users"  # pyright error: Expression of type "Literal['users']" cannot be assigned to declared type "declared_attr"
    name: str

Description

This will cause a type error when you declare __tablename__ with pyright as type checker. Like:

Expression of type "Literal['users']" cannot be assigned to declared type "declared_attr"

Operating System

Linux, macOS

Operating System Details

No response

SQLModel Version

0.0.4

Python Version

3.8.6

Additional Context

No response