Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused on Stubs providing type hints for Table constructor #229

Open
afreemanio opened this issue Sep 7, 2022 · 1 comment
Open

Confused on Stubs providing type hints for Table constructor #229

afreemanio opened this issue Sep 7, 2022 · 1 comment
Labels
question Further information is requested

Comments

@afreemanio
Copy link

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

@afreemanio afreemanio added the requires triage New issue that requires categorization label Sep 7, 2022
@CaselIT CaselIT added question Further information is requested and removed requires triage New issue that requires categorization labels Sep 8, 2022
@CaselIT
Copy link
Member

CaselIT commented Sep 8, 2022

Hi,

The current version of the stubs is alpha, and it's unlikely it will improve much, since work is now focussed on integrating the types into the sqlalchemy code for version 2.
PR are welcome to improve the many rough edges though

We are aware that the current story with typing is not great, but we are confident that sqlalchemy v2 will improve things a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants