diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-16 20:17:50 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-18 08:56:17 -0500 |
commit | 0e2b3aa323f62f46a342a8a8bba35323e214d300 (patch) | |
tree | 58d8279169e72305d5c18f338bb49e45766f6635 /lib/sqlalchemy/ext/mypy/plugin.py | |
parent | f91a25cd8191f026dd43c0a2475cda8a56d65c19 (diff) | |
download | sqlalchemy-0e2b3aa323f62f46a342a8a8bba35323e214d300.tar.gz |
mypy plugin fixes
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: https://github.com/sqlalchemy/sqlalchemy2-stubs/issues/236
Fixes: #9102
Change-Id: Ieb1bf7bf8184645bcd43253e57f1c267b2640537
Diffstat (limited to 'lib/sqlalchemy/ext/mypy/plugin.py')
-rw-r--r-- | lib/sqlalchemy/ext/mypy/plugin.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/sqlalchemy/ext/mypy/plugin.py b/lib/sqlalchemy/ext/mypy/plugin.py index e21f1fcb0..22e528387 100644 --- a/lib/sqlalchemy/ext/mypy/plugin.py +++ b/lib/sqlalchemy/ext/mypy/plugin.py @@ -201,10 +201,13 @@ def _fill_in_decorators(ctx: ClassDefContext) -> None: else: continue - assert isinstance(target.expr, NameExpr) - sym = ctx.api.lookup_qualified( - target.expr.name, target, suppress_errors=True - ) + if isinstance(target.expr, NameExpr): + sym = ctx.api.lookup_qualified( + target.expr.name, target, suppress_errors=True + ) + else: + continue + if sym and sym.node: sym_type = get_proper_type(sym.type) if isinstance(sym_type, Instance): |