Skip to content

Commit 796f1fa

Browse files
authored
Merge pull request #715 from Zeyad-Hassan-1/fix/issue-632-tuple-types
Fix tuple type support in typecheck() and flatmap inference (fixes #632)
2 parents 70957f1 + ed29edb commit 796f1fa

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

python/src/pywy/tests/test_word_count.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def config(pytestconfig):
5555

5656

5757
# TODO: implement tuple types support
58-
@pytest.mark.skip(reason="missing implementation for tuple types in operators")
58+
# @pytest.mark.skip(reason="missing implementation for tuple types in operators")
5959
def test_wordcount(config):
6060
with resources.path(resources_folder, "sample_data.md") as resource_path, \
6161
resources.path(resources_folder, "wordcount_out_python.txt") as output_path, \

python/src/pywy/types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616
#
1717

18+
import collections
1819
import re
1920

2021
from inspect import signature
@@ -175,7 +176,7 @@ def get_type_flatmap_function(call: FlatmapFunction) -> (type, type):
175176
)
176177
)
177178

178-
if type(sig.return_annotation) != type(Iterable):
179+
if get_origin(sig.return_annotation) is not collections.abc.Iterable:
179180
raise PywyException(
180181
"the return for the FlatmapFunction is not Iterable, {}".format(
181182
str(sig.return_annotation)
@@ -196,11 +197,15 @@ def typecheck(input_type: Type[ConstrainedOperatorType]):
196197

197198
if isinstance(input_type, List) and args:
198199
typecheck(args[0])
199-
elif isinstance(input_type, Tuple):
200+
elif get_origin(input_type) is tuple:
200201
if all(arg in allowed_types for arg in args):
201202
return
202203
else:
203204
raise TypeError(f"Unsupported Operator type: {input_type}")
205+
elif isinstance(input_type,tuple):
206+
for arg in input_type:
207+
typecheck(arg)
208+
return
204209
else:
205210
raise TypeError(f"Unsupported Operator type: {input_type}, {origin}, {args}")
206211

0 commit comments

Comments
 (0)