Skip to content

Commit

Permalink
Ensure type is properly initialized
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kaushik Ghose committed Jan 21, 2020
1 parent 2b10fa1 commit 30a2d63
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion benten/cwl/recordtype.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019 Seven Bridges. See LICENSE
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE

from typing import Dict

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

def init(self):
self.required_fields = set((k for k, v in self.fields.items() if v.required))
self.all_fields = set(self.fields.keys())

def check(self, node, node_key: str=None, map_sp: MapSubjectPredicate=None) -> TypeCheck:

if node is None:
Expand Down
4 changes: 3 additions & 1 deletion benten/cwl/specification.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Code to load the CWL specification from JSON and represent it as a
set of types"""

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

import json

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

lang_model[record_name].init()

return lang_model.get(record_name)


Expand Down
4 changes: 2 additions & 2 deletions benten/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright (c) 2019 Seven Bridges. See LICENSE
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE

__version__ = "2019.12.06"
__version__ = "2020.01.21"
5 changes: 4 additions & 1 deletion tests/test_language_specification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019 Seven Bridges. See LICENSE
# Copyright (c) 2019-2020 Seven Bridges. See LICENSE

import pathlib

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

# Ensure type is properly initialized after forward construction
assert "entry" in lang_model["Dirent"].required_fields


def test_forward_reference_resolution():
type_dict = parse_schema(schema_fname)
Expand Down

0 comments on commit 30a2d63

Please sign in to comment.