diff options
| author | Bryan Forbes <bryan@reigndropsfall.net> | 2021-04-12 16:24:37 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-13 15:40:34 -0400 |
| commit | d3c3982100a617623c92b41799b19f27448a1574 (patch) | |
| tree | c0e233880cdd31f3b07c7bfaf17e2d5c67bfc7e7 /lib/sqlalchemy | |
| parent | e365ef5bbad0516cbc9df0a4aea42c6d759a9c86 (diff) | |
| download | sqlalchemy-d3c3982100a617623c92b41799b19f27448a1574.tar.gz | |
Fix OrderingList handling
Revised the fix for ``OrderingList`` from version 1.4.7 which was testing
against the incorrect API.
Fixes: #6205
Change-Id: I1d3f8b6534b70ae000294c2a67f08117cb77ee99
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/ext/mypy/infer.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/mypy/infer.py b/lib/sqlalchemy/ext/mypy/infer.py index 7915c3ae2..d734d588e 100644 --- a/lib/sqlalchemy/ext/mypy/infer.py +++ b/lib/sqlalchemy/ext/mypy/infer.py @@ -13,6 +13,7 @@ from mypy.messages import format_type from mypy.nodes import AssignmentStmt from mypy.nodes import CallExpr from mypy.nodes import Expression +from mypy.nodes import FuncDef from mypy.nodes import MemberExpr from mypy.nodes import NameExpr from mypy.nodes import RefExpr @@ -22,6 +23,7 @@ from mypy.nodes import Var from mypy.plugin import SemanticAnalyzerPluginInterface from mypy.subtypes import is_subtype from mypy.types import AnyType +from mypy.types import CallableType from mypy.types import get_proper_type from mypy.types import Instance from mypy.types import NoneType @@ -125,6 +127,26 @@ def _infer_type_from_relationship( python_type_for_type = Instance( collection_cls_arg.node, [python_type_for_type] ) + elif ( + isinstance(collection_cls_arg, NameExpr) + and isinstance(collection_cls_arg.node, FuncDef) + and collection_cls_arg.node.type is not None + ): + if python_type_for_type is not None: + # this can still be overridden by the left hand side + # within _infer_Type_from_left_and_inferred_right + + # TODO: handle mypy.types.Overloaded + if isinstance(collection_cls_arg.node.type, CallableType): + rt = get_proper_type(collection_cls_arg.node.type.ret_type) + + if isinstance(rt, CallableType): + callable_ret_type = get_proper_type(rt.ret_type) + if isinstance(callable_ret_type, Instance): + python_type_for_type = Instance( + callable_ret_type.type, + [python_type_for_type], + ) else: util.fail( api, |
