Description
Describe your question
I'm a new user to SQLAlchemy and I'm confused on the current state of stubs. Using the pylance/typeshed stubs as well as the dropbox stubs give me issues when following the official documentation (like, from sqlalchemy.orm import Session, declarative_base, says that declarative_base is not part of the package), and when reading the documentation, it suggests to use this package, which is fine and I get it all working, but when I am hovering over an instance of Table from sqlalchemy.schema, it gives me the constructor information of:
Table(*args: Any, **kw: Any)
Constructor for _schema.Table.
This method is a no-op. See the top-level documentation for _schema.Table for constructor arguments.
While the stubs from sqlalchemy-stubs gives me:
Table(name: str, metadata: MetaData, *args: Any, autoload: bool = ..., autoload_replace: bool = ..., autoload_with: Engine | Connection = ..., extend_existing: bool = ..., implicit_returning: bool = ..., include_columns: Sequence[str] = ..., info: Mapping[str, Any] = ..., keep_existing: bool = ..., listeners: Sequence[Tuple[str, (...) -> Any]] = ..., mustexist: bool = ..., prefixes: Sequence[str] = ..., quote: bool | None = ..., quote_schema: bool | None = ..., schema: str | None = ..., comment: str = ..., **kw: Any)
Constructor for _schema.Table.
This method is a no-op. See the top-level documentation for _schema.Table for constructor arguments.
So, the stubs from sqlalchemy-stubs give me type hinting for the arguments for Table, and the ones for this package do not. Is this intentional?
Also, when it is asking me to see the top-level documentation for _schema.Table, where am I supposed to look, and how can I see this in code? How can I have this package give me an error when I supply incorrect arguments to a table constructor (like its supposed to), or is this some sort of regression when compared to the other packages? I'm sure I'm just not understanding, and I'd love to make an update to the docs for this plugin if it's just something I'm not getting.
I got to this point by following the core tutorial up until the metadata section - https://docs.sqlalchemy.org/en/14/tutorial/metadata.html#setting-up-metadata-with-table-objects
Example
from sqlalchemy import ( # ,
Column,
Integer,
MetaData,
String,
Table,
text,
)
from sqlalchemy.orm import Session, declarative_base
metadata_obj = MetaData()
user_table = Table(
"user_account",
metadata_obj,
Column("id", Integer, primary_key=True),
Column("name", String(30)),
Column("fullname", String),
)
Versions
- OS: Ubuntu 20.04
- Python: 3.10.6
- SQLAlchemy: 1.4.41
- mypy: 0.971
- SQLAlchemy2-stubs: 0.0.2a27
Additional context
I'm using vscode