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

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

Closed
wyattscarpenter opened this issue Mar 30, 2024 · 2 comments

Comments

@wyattscarpenter
Copy link
Contributor

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!

benc-db pushed a commit that referenced this issue Apr 2, 2024
* Create py.typed

Signed-off-by: wyattscarpenter <[email protected]>

* add -> Connection annotation

Signed-off-by: wyattscarpenter <[email protected]>

* massage the code to appease the particular version of the project's mypy deps

Signed-off-by: wyattscarpenter <[email protected]>

* fix circular import problem

Signed-off-by: wyattscarpenter <[email protected]>

---------

Signed-off-by: wyattscarpenter <[email protected]>
@wyattscarpenter
Copy link
Contributor Author

I realized error №3 here was not fixed by solving №s 1 and 2, but also I realized what was causing it, leading to my fix in #384

@wyattscarpenter
Copy link
Contributor Author

Since #382 and #384 have been merged, I'm fairly certain this problem is completely fixed. 🎉

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

No branches or pull requests

1 participant