Skip to content

Fixing a couple type problems. (adding py.typed, typing connect, returning Any from fetchall (which I failed to fix!)) #381

Closed
@wyattscarpenter

Description

@wyattscarpenter

I'm trying to use databricks-sql-python in a statically-typed python project, and I'm running into some issues. I'm using mypy --strict.

  1. Despite this project having type annotations, my typechecker (mypy) will not check them (this causes problems for the type implications of the rest of my code). I'm pretty sure that, as per https://peps.python.org/pep-0561/#packaging-type-information, you can just add a py.typed file to the sql/ and sqlalchemy/ folders. I don't use the sqlalchemy side so I haven't tested that, but the sql one seems to work perfectly when I modify the copy of databricks-sql-python on my machine.

  2. I get error: Call to untyped function "connect" in typed context [no-untyped-call]. I'm pretty sure you can just change the type signature of def connect in the sql folder's __init.py__ to def connect(server_hostname, http_path, access_token=None, **kwargs) -> "Connection". This works perfectly when I test it on my machine.

  3. I get error: Returning Any from function declared to return "List[Row]" [no-any-return] when I have the line return cursor.execute(query, sql_params_dict).fetchall(). Honestly, I have no idea how to fix this. fetchall looks like it has the right type signature to me! Maybe this is a bug in mypy somehow? Or maybe this is a symptom of the previous issue not getting completely fixed...

I can make a pull request about this, at least the first two, but maybe these ideas are bad and you haven't done them yet because it would break something else; let me know!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions