mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-19 23:21:57 -04:00
accommodate no cls info found in _scan_declarative
Fixed issue in mypy plugin where class info for a custom declarative base would not be handled correctly on a cached mypy pass, leading to an AssertionError being raised. Fixes: #6476 Change-Id: If78340673e6a4d16d8f7cf787ce3bdb02c8bd47b
This commit is contained in:
+7
@@ -0,0 +1,7 @@
|
||||
.. change::
|
||||
:tags: bug, mypy
|
||||
:tickets: 6476
|
||||
|
||||
Fixed issue in mypy plugin where class info for a custom declarative base
|
||||
would not be handled correctly on a cached mypy pass, leading to an
|
||||
AssertionError being raised.
|
||||
@@ -50,7 +50,10 @@ def _scan_declarative_assignments_and_apply_types(
|
||||
|
||||
info = util._info_for_cls(cls, api)
|
||||
|
||||
if cls.fullname.startswith("builtins"):
|
||||
if info is None:
|
||||
# this can occur during cached passes
|
||||
return None
|
||||
elif cls.fullname.startswith("builtins"):
|
||||
return None
|
||||
elif "_sa_decl_class_applied" in info.metadata:
|
||||
cls_metadata = util.DeclClassApplied.deserialize(
|
||||
|
||||
@@ -208,6 +208,8 @@ def _info_for_cls(
|
||||
) -> TypeInfo:
|
||||
if cls.info is CLASSDEF_NO_INFO:
|
||||
sym = api.lookup_qualified(cls.name, cls)
|
||||
if sym is None:
|
||||
return None
|
||||
assert sym and isinstance(sym.node, TypeInfo)
|
||||
return sym.node
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
|
||||
class CustomBase:
|
||||
x = 5
|
||||
|
||||
|
||||
sql_base = declarative_base(cls=CustomBase)
|
||||
@@ -0,0 +1,7 @@
|
||||
--- a/table.py 2021-06-21 12:16:35.418148313 -0400
|
||||
+++ b/table.py 2021-06-21 12:16:31.204108368 -0400
|
||||
@@ -3,3 +3,4 @@
|
||||
class Table(sql_base):
|
||||
pass
|
||||
|
||||
+x = Table.x
|
||||
@@ -0,0 +1,5 @@
|
||||
from .base import sql_base
|
||||
|
||||
|
||||
class Table(sql_base):
|
||||
pass
|
||||
Reference in New Issue
Block a user