-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjustments made to the mypy plugin to accommodate for some potential changes being made for issue #236 sqlalchemy2-stubs when using SQLAlchemy 1.4. These changes are being kept in sync within SQLAlchemy 2.0. The changes are also backwards compatible with older versions of sqlalchemy2-stubs. Fixed crash in mypy plugin which could occur on both 1.4 and 2.0 versions if a decorator for the :func:`_orm.registry.mapped` decorator were used that was referenced in an expression with more than two components (e.g. ``@Backend.mapper_registry.mapped``). This scenario is now ignored; when using the plugin, the decorator expression needs to be two components (i.e. ``@reg.mapped``). References: sqlalchemy/sqlalchemy2-stubs#236 Fixes: #9102 Change-Id: Ieb1bf7bf8184645bcd43253e57f1c267b2640537
- Loading branch information
Showing
5 changed files
with
78 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.. change:: | ||
:tags: bug, mypy | ||
:versions: 2.0.0rc3 | ||
|
||
Adjustments made to the mypy plugin to accommodate for some potential | ||
changes being made for issue #236 sqlalchemy2-stubs when using SQLAlchemy | ||
1.4. These changes are being kept in sync within SQLAlchemy 2.0. | ||
The changes are also backwards compatible with older versions of | ||
sqlalchemy2-stubs. | ||
|
||
|
||
.. change:: | ||
:tags: bug, mypy | ||
:tickets: 9102 | ||
:versions: 2.0.0rc3 | ||
|
||
Fixed crash in mypy plugin which could occur on both 1.4 and 2.0 versions | ||
if a decorator for the :func:`_orm.registry.mapped` decorator were used | ||
that was referenced in an expression with more than two components (e.g. | ||
``@Backend.mapper_registry.mapped``). This scenario is now ignored; when | ||
using the plugin, the decorator expression needs to be two components (i.e. | ||
``@reg.mapped``). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from sqlalchemy import Column | ||
from sqlalchemy import Integer | ||
from sqlalchemy.orm import registry | ||
|
||
|
||
class BackendMeta: | ||
__abstract__ = True | ||
mapped_registry: registry = registry() | ||
metadata = mapped_registry.metadata | ||
|
||
|
||
# this decorator is not picked up now, but at least it doesn't crash | ||
@BackendMeta.mapped_registry.mapped | ||
class User: | ||
__tablename__ = "user" | ||
|
||
# EXPECTED_MYPY: Incompatible types in assignment (expression has type "Column[int]", variable has type "int") | ||
id: int = Column(Integer(), primary_key=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from sqlalchemy import Column | ||
from sqlalchemy import Integer | ||
from sqlalchemy.orm import registry | ||
|
||
|
||
class BackendMeta: | ||
__abstract__ = True | ||
mapped_registry: registry = registry() | ||
metadata = mapped_registry.metadata | ||
|
||
|
||
reg: registry = BackendMeta.mapped_registry | ||
|
||
|
||
@reg.mapped | ||
class User: | ||
__tablename__ = "user" | ||
|
||
id: int = Column(Integer(), primary_key=True) |