summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/mypy/infer.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-08-27 11:39:55 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-08-27 16:04:24 -0400
commit94dfe0dfd7f7e69588d06dcf2ca74a3fce6ad4fc (patch)
tree7241822c9250204b8636957d9dc4239044a74118 /lib/sqlalchemy/ext/mypy/infer.py
parente2d9ef3fe6f7bd9b151caf71ae5eb7f15522ec8c (diff)
downloadsqlalchemy-94dfe0dfd7f7e69588d06dcf2ca74a3fce6ad4fc.tar.gz
dont assume argument lists for column property
Fixed issue where mypy plugin would crash when interpreting a ``query_expression()`` construct. Fixes: #6950 Change-Id: Ic1f28d135bf6eb05c92061430c0d5a3663b804ef
Diffstat (limited to 'lib/sqlalchemy/ext/mypy/infer.py')
-rw-r--r--lib/sqlalchemy/ext/mypy/infer.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/sqlalchemy/ext/mypy/infer.py b/lib/sqlalchemy/ext/mypy/infer.py
index 85a94bba6..52570f772 100644
--- a/lib/sqlalchemy/ext/mypy/infer.py
+++ b/lib/sqlalchemy/ext/mypy/infer.py
@@ -284,20 +284,35 @@ def _infer_type_from_decl_column_property(
"""
assert isinstance(stmt.rvalue, CallExpr)
- first_prop_arg = stmt.rvalue.args[0]
- if isinstance(first_prop_arg, CallExpr):
- type_id = names.type_id_for_callee(first_prop_arg.callee)
+ if stmt.rvalue.args:
+ first_prop_arg = stmt.rvalue.args[0]
+
+ if isinstance(first_prop_arg, CallExpr):
+ type_id = names.type_id_for_callee(first_prop_arg.callee)
+
+ # look for column_property() / deferred() etc with Column as first
+ # argument
+ if type_id is names.COLUMN:
+ return _infer_type_from_decl_column(
+ api,
+ stmt,
+ node,
+ left_hand_explicit_type,
+ right_hand_expression=first_prop_arg,
+ )
- # look for column_property() / deferred() etc with Column as first
- # argument
- if type_id is names.COLUMN:
+ if isinstance(stmt.rvalue, CallExpr):
+ type_id = names.type_id_for_callee(stmt.rvalue.callee)
+ # this is probably not strictly necessary as we have to use the left
+ # hand type for query expression in any case. any other no-arg
+ # column prop objects would go here also
+ if type_id is names.QUERY_EXPRESSION:
return _infer_type_from_decl_column(
api,
stmt,
node,
left_hand_explicit_type,
- right_hand_expression=first_prop_arg,
)
return infer_type_from_left_hand_type_only(