Skip to content

Commit

Permalink
update linter
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed May 20, 2021
1 parent ce1a22b commit c38df32
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions WDL/Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,10 @@ def decl(self, obj: Tree.Decl) -> Any:
def call(self, obj: Tree.Call) -> Any:
for name, inp_expr in obj.inputs.items():
decl = _find_input_decl(obj, name)
if not inp_expr.type.coerces(decl.type, check_quant=True) and not _is_array_coercion(
decl.type, inp_expr.type
# implicitly consider optional, the type of an input with a default
decltype = decl.type.copy(optional=True) if decl.expr else decl.type
if not inp_expr.type.coerces(decltype, check_quant=True) and not _is_array_coercion(
decltype, inp_expr.type
):
msg = "input {} {} = :{}:".format(str(decl.type), decl.name, str(inp_expr.type))
self.add(obj, msg, inp_expr.pos)
Expand Down
6 changes: 3 additions & 3 deletions WDL/Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,13 @@ def typecheck_input(
for name, expr in self.inputs.items():
try:
decl = self.callee.available_inputs[name]
# implicitly consider optional, the type of an input with a default
decltype = decl.type.copy(optional=True) if decl.expr else decl.type
errors.try1(
lambda expr=expr, decl=decl: expr.infer_type(
type_env, stdlib, check_quant=check_quant, struct_types=struct_types
).typecheck(decl.type.copy(optional=True) if decl.expr else decl.type)
).typecheck(decltype)
)
# If the input includes a default, then we implicitly made None acceptable even
# if the declared type wasn't optional.
except KeyError:
errors.append(Error.NoSuchInput(expr, name))
if name in required_inputs:
Expand Down
6 changes: 4 additions & 2 deletions WDL/runtime/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,10 @@ def __getstate__(self) -> Dict[str, Any]:
def _coerce_call_inputs(
input_values: Env.Bindings[Value.Base], input_decls: Env.Bindings[Tree.Decl]
) -> Env.Bindings[Value.Base]:
# fixup pass: if explicit None value is supplied for an input that has a default value AND a
# non-optional type, make it as if the value were absent (so that the default will be used)
# Fixup pass: if None value is supplied for an input that has a default expression AND
# non-optional type, remove the value entirely so that the default will be used.
# In contrast, if the input declaration has an -explicitly- optional type, then we do pass None
# to override the default, if any.
input_values = input_values.filter(
lambda b: not (
isinstance(b.value, Value.Null)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_3corpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class BioWDLTasks(unittest.TestCase):
@wdl_corpus(
["test_corpi/biowdl/aligning/**"],
expected_lint={
"OptionalCoercion": 12,
"OptionalCoercion": 11,
"UnusedDeclaration": 12,
"NonemptyCoercion": 1,
"NameCollision": 1,
Expand Down Expand Up @@ -507,7 +507,6 @@ class BioWDLSomaticVariantCalling(unittest.TestCase):
expected_lint={
"UnusedDeclaration": 8,
"SelectArray": 2,
"OptionalCoercion": 2,
"NonemptyCoercion": 3,
"UnusedCall": 1,
"UnverifiedStruct": 1,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_7runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,3 +956,5 @@ def test_implicitly_optional_input_with_default(self):
self.assertEqual(outp["results"], ["AliceCarol", None])
outp = self._run(caller, {"b": "Bas"})
self.assertEqual(outp["results"], ["AliceBas", "Bas"])
outp = self._run(caller, {"a": "Alyssa"})
self.assertEqual(outp["results"], ["Alyssa", None])

0 comments on commit c38df32

Please sign in to comment.