From ccdd58b336cd623d9cd0de4e46b179f235679ec3 Mon Sep 17 00:00:00 2001 From: antonio2368 Date: Tue, 27 Apr 2021 08:31:18 +0200 Subject: [PATCH] Fix parsing nested complex types (#142) * Fix parsing of types for mgp.List --- CHANGELOG.md | 7 +++++++ include/mgp.py | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8e1af591..ccc88cab7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## Future +### Bug Fixes + +* Fixed parsing of types for Python procedures for types nested in `mgp.List`. + For example, parsing of `mgp.List[mgp.Map]` works now. + +## v1.4.0 + ### Breaking Changes * Changed `MEMORY LIMIT num (KB|MB)` clause in the procedure calls to `PROCEDURE MEMORY LIMIT num (KB|MB)`. diff --git a/include/mgp.py b/include/mgp.py index b2719d8fc..a0f7bab50 100644 --- a/include/mgp.py +++ b/include/mgp.py @@ -683,7 +683,15 @@ def _typing_to_cypher_type(type_): return _mgp.type_nullable(simple_type) return _mgp.type_nullable(parse_typing(type_arg_as_str)) elif type_as_str.startswith('typing.List'): - type_arg_as_str, = parse_type_args(type_as_str) + type_arg_as_str = parse_type_args(type_as_str) + + if len(type_arg_as_str) > 1: + # Nested object could be a type consisting of a list of types (e.g. mgp.Map) + # so we need to join the parts. + type_arg_as_str = ', '.join(type_arg_as_str) + else: + type_arg_as_str = type_arg_as_str[0] + simple_type = get_simple_type(type_arg_as_str) if simple_type is not None: return _mgp.type_list(simple_type)