Using reserved keywords or built-in functions as variable/attribute names is commonly seen as bad practice.
However, the SQLALchemy tutorial is full of exampled with attributes named id
.
Straight from the tutorial
>>> class User(Base):
... __tablename__ = "user_account"
...
... id: Mapped[int] = mapped_column(primary_key=True)
... name: Mapped[str] = mapped_column(String(30))
... fullname: Mapped[Optional[str]]
...
... addresses: Mapped[List["Address"]] = relationship(
... back_populates="user", cascade="all, delete-orphan"
... )
...
... def __repr__(self) -> str:
... return f"User(id={self.id!r}, name={self.name!r}, fullname={self.fullname!r})"
Why is it not recommended to use id_
instead, as recommended at least for keywords in PEP 8?