Skip to content

Commit 30a2d63

Browse files
author
Kaushik Ghose
committed
Ensure type is properly initialized
Commit 8a8deee handles self-references in the specification by placing the still being constructed type in the type dict before recursing into its children. This is the correct thing to do, but we forgot that now the type information is incomplete when it is initialized. Therefore the `required_fields` and `all_fields` variables were not set correctly. This caused type inference to fail in particular cases such as for `Dirent` We now re-run the init (the setup) once the type is completely constructed ... Version bumped to 2020.01.21. Happy New Year! Closes #77 Closes #76
1 parent 2b10fa1 commit 30a2d63

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

benten/cwl/recordtype.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019 Seven Bridges. See LICENSE
1+
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE
22

33
from typing import Dict
44

@@ -28,6 +28,10 @@ def __init__(self, name: str, doc: str, fields: Dict[str, 'CWLFieldType']):
2828
self.required_fields = set((k for k, v in self.fields.items() if v.required))
2929
self.all_fields = set(self.fields.keys())
3030

31+
def init(self):
32+
self.required_fields = set((k for k, v in self.fields.items() if v.required))
33+
self.all_fields = set(self.fields.keys())
34+
3135
def check(self, node, node_key: str=None, map_sp: MapSubjectPredicate=None) -> TypeCheck:
3236

3337
if node is None:

benten/cwl/specification.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Code to load the CWL specification from JSON and represent it as a
22
set of types"""
33

4-
# Copyright (c) 2019 Seven Bridges. See LICENSE
4+
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE
55

66
import json
77

@@ -128,6 +128,8 @@ def parse_record(schema, lang_model):
128128
for field in schema.get("fields") for k, v in [parse_field(field, lang_model)]
129129
})
130130

131+
lang_model[record_name].init()
132+
131133
return lang_model.get(record_name)
132134

133135

benten/version.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Copyright (c) 2019 Seven Bridges. See LICENSE
1+
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE
22

3-
__version__ = "2019.12.06"
3+
__version__ = "2020.01.21"

tests/test_language_specification.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019 Seven Bridges. See LICENSE
1+
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE
22

33
import pathlib
44

@@ -21,6 +21,9 @@ def test_load_language_specification():
2121
assert "steps" in lang_model["Workflow"].fields
2222
assert lang_model["Workflow"].fields["steps"].required
2323

24+
# Ensure type is properly initialized after forward construction
25+
assert "entry" in lang_model["Dirent"].required_fields
26+
2427

2528
def test_forward_reference_resolution():
2629
type_dict = parse_schema(schema_fname)

0 commit comments

Comments
 (0)