Skip to content

Combine microsoft/python-type-stubs/sqlalchemy #9597

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

Closed
wants to merge 43 commits into from

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Jan 28, 2023

Includes #9596 and #9568, so merge those first. (keeping this as draft until then, I've also yet to self-review my own PR with a fresh mind)
If you'd like me to split up this PR (maybe you'd like to review a specific section in isolation) and you can think of a decent way to do so, let me know.
In the same vein, I'd rather not add more type-hints, even if they seem obvious (unless it's to fix an issue). I would consider it scope-creeping given the motivation behind this PR: #9595 (comment)

Brings types-sqlalchemy on par with https://github.com/microsoft/python-type-stubs/tree/main/sqlalchemy and https://github.com/dropbox/sqlalchemy-stubs. Except for making most classes (mainly Column and Row related ones) generic. As that would cause hundreds, if not thousands of additional (and unhelpful) mypy_primer differences. It also helps keep this PR more manageable and focus on the non-generic type issues.

Merged stubs, avoided new generics, manually reviewed possible types and fixed existing type issues I found.
Standardized imports (relative seems to be preferred for this stub) and fixed a handful of pytype references issues with imports. (google/pytype#1087)
I tried my best to fully comment the confusing parts.

@Avasam Avasam marked this pull request as draft January 28, 2023 10:32
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Avasam Avasam changed the title Merge microsoft/python-type-stubs/sqlalchemy Combine microsoft/python-type-stubs/sqlalchemy Jan 30, 2023
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Avasam
Copy link
Collaborator Author

Avasam commented Feb 16, 2023

@hauntsaninja I have a mypy_primer question for you. What's up with these diff lines -->
image

And does it mean anything to us or is it related to: https://github.com/hauntsaninja/mypy_primer/blob/master/mypy_primer.py#L521

Edit: no longer an issue

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Avasam
Copy link
Collaborator Author

Avasam commented May 20, 2023

I'm not getting this pytype error locally with WSL.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2023

Diff from mypy_primer, showing the effect of this PR on open source code:

optuna (https://github.com/optuna/optuna)
- optuna/storages/_rdb/models.py:64: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:72: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:119: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:151: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:187: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:213: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:245: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:290: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:322: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:377: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:451: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:524: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
+ optuna/storages/_rdb/models.py:571: error: Incompatible return value type (got "Optional[VersionInfoModel]", expected "VersionInfoModel")  [return-value]
- optuna/storages/_rdb/models.py:556: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/models.py:569: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/storage.py:757: error: Call to untyped function "one_or_none" in typed context  [no-untyped-call]
- optuna/storages/_rdb/storage.py:807: error: Incompatible types in assignment (expression has type "Set[Any]", variable has type "List[Tuple[Any]]")  [assignment]
+ optuna/storages/_rdb/storage.py:807: error: Incompatible types in assignment (expression has type "Set[Any]", variable has type "List[Any]")  [assignment]
- optuna/storages/_rdb/storage.py:1143: error: Incompatible return value type (got "ColumnOperators[Any]", expected "bool")  [return-value]
+ optuna/storages/_rdb/storage.py:1143: error: Incompatible return value type (got "Union[BinaryExpression, bool]", expected "bool")  [return-value]

prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/server/utilities/database.py:240: error: Incompatible types in assignment (expression has type "Timestamp", base class "ColumnElement" defined the type as "Callable[[ColumnElement[Any]], Optional[TypeEngine]]")  [assignment]
+ src/prefect/server/utilities/database.py:277: error: Incompatible types in assignment (expression has type "Timestamp", base class "ColumnElement" defined the type as "Callable[[ColumnElement[Any]], Optional[TypeEngine]]")  [assignment]
+ src/prefect/server/utilities/database.py:330: error: Incompatible types in assignment (expression has type "Interval", base class "ColumnElement" defined the type as "Callable[[ColumnElement[Any]], Optional[TypeEngine]]")  [assignment]
+ src/prefect/server/utilities/database.py:382: error: Incompatible types in assignment (expression has type "Interval", base class "ColumnElement" defined the type as "Callable[[ColumnElement[Any]], Optional[TypeEngine]]")  [assignment]
+ src/prefect/server/database/query_components.py:422: error: Incompatible types in assignment (expression has type "CTE", variable has type "Select")  [assignment]
+ src/prefect/server/models/block_registration.py:137: error: "SessionTransaction" has no attribute "__aenter__"  [attr-defined]
+ src/prefect/server/models/block_registration.py:137: error: "SessionTransaction" has no attribute "__aexit__"  [attr-defined]
+ src/prefect/server/models/block_registration.py:159: error: "SessionTransaction" has no attribute "__aenter__"  [attr-defined]
+ src/prefect/server/models/block_registration.py:159: error: "SessionTransaction" has no attribute "__aexit__"  [attr-defined]
+ src/prefect/server/models/block_documents.py:306: error: Incompatible types in assignment (expression has type "CTE", variable has type "Select")  [assignment]

ibis (https://github.com/ibis-project/ibis)
+ ibis/backends/base/sql/alchemy/registry.py:21: error: Incompatible types in assignment (expression has type "String", base class "GenericFunction" defined the type as "Callable[[GenericFunction], Union[TypeEngine, Type[TypeEngine]]]")  [assignment]
- ibis/backends/base/sql/alchemy/datatypes.py:20: error: Module has no attribute "to_instance"  [attr-defined]
- ibis/backends/base/sql/alchemy/datatypes.py:44: error: Module has no attribute "to_instance"  [attr-defined]
- ibis/backends/base/sql/alchemy/datatypes.py:60: error: Module has no attribute "to_instance"  [attr-defined]
- ibis/backends/base/sql/alchemy/datatypes.py:61: error: Module has no attribute "to_instance"  [attr-defined]
+ ibis/backends/base/sql/alchemy/__init__.py:152: error: Module has no attribute "registry"  [attr-defined]
+ ibis/backends/base/sql/alchemy/__init__.py:527: error: List item 1 has incompatible type "str"; expected "None"  [list-item]
+ ibis/backends/druid/__init__.py:51: error: Incompatible types in assignment (expression has type "Callable[[Any, str, Any], bool]", variable has type "Callable[[Any, Any, Optional[Any], KwArg(Any)], bool]")  [assignment]
- ibis/backends/snowflake/__init__.py:153: error: Module has no attribute "to_instance"  [attr-defined]
- ibis/backends/snowflake/__init__.py:439: error: Module has no attribute "to_instance"  [attr-defined]
- ibis/backends/druid/__init__.py:51: error: Incompatible types in assignment (expression has type "Callable[[Any, str, Any], bool]", variable has type "Callable[[Any, Any, Optional[Any], KwArg(Any)], None]")  [assignment]

@Avasam Avasam deleted the sqlalchemy-from-python-type-stubs branch July 8, 2023 18:34
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