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

SQLAlchemy 2: Fix failing mypy checks from development #257

Merged
merged 14 commits into from
Oct 23, 2023

Conversation

susodapop
Copy link
Contributor

@susodapop susodapop commented Oct 23, 2023

Description

Now that we've implemented SQLAlchemy 2 support, I'm cleaning up the failing mypy checks. There are three broad kinds of fixes here:

  • Fix incorrect type declarations
  • Skip type enforcement for interfaces from sqlalchemy.interfaces
  • Skip type enforcement for certain nullable cases

In one case, I modified the actual behaviour of the dialect in order to keep the type hints as-is. I did this by moving a call to .all() on a CursorResult from the top-level method in base.py into the _parse method that it depends on.

This will fix the failing mypy checks on main which have been entirely driven by SQLAlchemy development. For future features like this, we should use a staging branch so that main doesn't fail for unreleased features.

sqlalchemy.interfaces

In the top-level dialect in base.py I use the type hints that SQLAlchemy expects internally. Although these aren't enforced by Python, it's useful for developers reading the source to understand what's happening when methods like get_foreign_keys and get_pk_constraint is called. Rather than update the type hints to something mypy can parse, I left the hints as-is. We should figure out how to write these methods in a way that actually enforces the interface.

Jesse Whitehouse added 14 commits October 23, 2023 16:23
mypy doesn't like wildcard imports, but they are necessary here and con
-sistent with SQLAlchemy's guidance for structuring tests

Signed-off-by: Jesse Whitehouse <[email protected]>
I changed the format of the output of dialect._describe_table_extended
to return a list of dicts rather than a list of lists but didn't update
this type hint

Signed-off-by: Jesse Whitehouse <[email protected]>
This method doesn't handle cases where the regex doesn't match anything

Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
base.py.

I re-ran HasTableTest which depend on this working to confirm that
it does not cause a regression.

Signed-off-by: Jesse Whitehouse <[email protected]>
I'm not clear how to instruct mypy to know that the value of
`result` will never be None given the way we called _describe_table_extended

Signed-off-by: Jesse Whitehouse <[email protected]>
mypy doesn't understand that describe_table_extended will never return a
NoneType under these circumstances

Signed-off-by: Jesse Whitehouse <[email protected]>
Not sure how we can actually match the interface mypy expects

Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
@susodapop susodapop merged commit b2b2d2a into main Oct 23, 2023
@susodapop susodapop deleted the fix-sqlalchemy-types branch October 23, 2023 21:03
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

Successfully merging this pull request may close these issues.

2 participants