Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ ci_housekeeping: check_check check doc
ci_unit_tests: unit_tests

check:
ruff check --ignore E741 WDL
ruff check WDL
mypy WDL
ruff format --check --line-length 100 WDL
ruff format --check WDL

check_check:
# regression test against pyre/mypy doing nothing (issue #100)
Expand All @@ -54,7 +54,7 @@ check_check:
rm WDL/DELETEME_check_check.py

pretty:
ruff format --line-length 100 WDL
ruff format WDL

# build docker image with current source tree, poised to run tests e.g.:
# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp miniwdl
Expand Down
4 changes: 2 additions & 2 deletions WDL/Expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def infer_type(
assert isinstance(child, Base)
errors.try1(
(
lambda child: lambda: child.infer_type(
type_env, stdlib, check_quant, struct_types
lambda child: (
lambda: child.infer_type(type_env, stdlib, check_quant, struct_types)
)
)(child)
)
Expand Down
58 changes: 34 additions & 24 deletions WDL/Lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ def _compound_coercion(
if predicates:
return predicates(to_type, from_type)
if not from_type_predicate:
from_type_predicate = lambda ty: not isinstance( # noqa: E731
ty, (base_to_type, Type.Any)
from_type_predicate = lambda ty: (
not isinstance( # noqa: E731
ty, (base_to_type, Type.Any)
)
)
return from_type_predicate(from_type)
return False
Expand Down Expand Up @@ -238,13 +240,15 @@ def decl(self, obj: Tree.Decl) -> Any:
obj.type,
obj.expr.type,
(Type.String,),
lambda from_type: not isinstance(
from_type,
(
(Type.Any, Type.String, Type.File, Type.Directory)
if isinstance(_parent_executable(obj), Tree.Task)
else (Type.Any, Type.String)
),
lambda from_type: (
not isinstance(
from_type,
(
(Type.Any, Type.String, Type.File, Type.Directory)
if isinstance(_parent_executable(obj), Tree.Task)
else (Type.Any, Type.String)
),
)
),
):
self.add(obj, "{} {} = :{}:".format(str(obj.type), obj.name, str(obj.expr.type)))
Expand Down Expand Up @@ -300,18 +304,20 @@ def expr(self, obj: Expr.Base) -> Any:
F_i,
arg_i.type,
(Type.String,),
lambda from_type: not isinstance(
from_type,
(
lambda from_type: (
not isinstance(
from_type,
(
Type.Any,
Type.String,
Type.File,
Type.Directory,
)
if isinstance(_parent_executable(obj), Tree.Task)
else (Type.Any, Type.String)
),
(
Type.Any,
Type.String,
Type.File,
Type.Directory,
)
if isinstance(_parent_executable(obj), Tree.Task)
else (Type.Any, Type.String)
),
)
),
):
msg = "{} argument of {}() = :{}:".format(
Expand Down Expand Up @@ -465,8 +471,10 @@ def decl(self, obj: Tree.Decl) -> Any:
obj.type,
obj.expr.type,
(Type.StructInstance,),
lambda from_type: isinstance(from_type, Type.Any)
or (isinstance(from_type, Type.Map) and from_type.literal_keys is None),
lambda from_type: (
isinstance(from_type, Type.Any)
or (isinstance(from_type, Type.Map) and from_type.literal_keys is None)
),
):
self.add(
obj,
Expand All @@ -482,8 +490,10 @@ def call(self, obj: Tree.Call) -> Any:
decl.type,
inp_expr.type,
(Type.StructInstance,),
lambda from_type: isinstance(from_type, Type.Any)
or (isinstance(from_type, Type.Map) and from_type.literal_keys is None),
lambda from_type: (
isinstance(from_type, Type.Any)
or (isinstance(from_type, Type.Map) and from_type.literal_keys is None)
),
):
msg = "input {} {} = :{}: -- struct initializer isn't statically verified".format(
str(decl.type), decl.name, str(inp_expr.type)
Expand Down
57 changes: 36 additions & 21 deletions WDL/Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,10 @@ def typecheck(
for _, runtime_expr in self.runtime.items():
errors.try1(
(
lambda runtime_expr: lambda: runtime_expr.infer_type(
type_env, stdlib, check_quant=check_quant, struct_types=struct_types
lambda runtime_expr: (
lambda: runtime_expr.infer_type(
type_env, stdlib, check_quant=check_quant, struct_types=struct_types
)
)
)(runtime_expr)
) # .typecheck()
Expand Down Expand Up @@ -644,9 +646,14 @@ def typecheck_input(
decltype = decl.type.copy(optional=True) if decl.expr else decl.type
errors.try1(
(
lambda expr, decltype: lambda: expr.infer_type(
type_env, stdlib, check_quant=check_quant, struct_types=struct_types
).typecheck(decltype)
lambda expr, decltype: (
lambda: expr.infer_type(
type_env,
stdlib,
check_quant=check_quant,
struct_types=struct_types,
).typecheck(decltype)
)
)(expr, decltype)
)
except KeyError:
Expand Down Expand Up @@ -1157,11 +1164,13 @@ def typecheck(self, doc: "Document", check_quant: bool) -> None:
for decl in self.inputs or []:
errors.try1(
(
lambda decl, type_env: lambda: decl.typecheck(
type_env,
stdlib,
check_quant=check_quant,
struct_types=doc._struct_types,
lambda decl, type_env: (
lambda: decl.typecheck(
type_env,
stdlib,
check_quant=check_quant,
struct_types=doc._struct_types,
)
)
)(decl, self._type_env)
)
Expand Down Expand Up @@ -1482,8 +1491,8 @@ def typecheck(self, check_quant: bool = True) -> None:
names.add(task.name)
errors.try1(
(
lambda task: lambda: task.typecheck(
self._struct_types, check_quant=check_quant
lambda task: (
lambda: task.typecheck(self._struct_types, check_quant=check_quant)
)
)(task)
)
Expand Down Expand Up @@ -1768,11 +1777,13 @@ def _typecheck_workflow_body(
_translate_struct_mismatch(
doc,
(
lambda child, type_env: lambda: child.typecheck(
type_env,
stdlib,
check_quant=check_quant,
struct_types=doc._struct_types,
lambda child, type_env: (
lambda: child.typecheck(
type_env,
stdlib,
check_quant=check_quant,
struct_types=doc._struct_types,
)
)
)(child, self._type_env),
)
Expand All @@ -1783,8 +1794,10 @@ def _typecheck_workflow_body(
_translate_struct_mismatch(
doc,
(
lambda child, type_env: lambda: child.typecheck_input(
doc._struct_types, type_env, stdlib, check_quant=check_quant
lambda child, type_env: (
lambda: child.typecheck_input(
doc._struct_types, type_env, stdlib, check_quant=check_quant
)
)
)(child, self._type_env),
)
Expand All @@ -1798,8 +1811,10 @@ def _typecheck_workflow_body(
_translate_struct_mismatch(
doc,
(
lambda child: lambda: _typecheck_workflow_body(
doc, stdlib, check_quant, child
lambda child: (
lambda: _typecheck_workflow_body(
doc, stdlib, check_quant, child
)
)
)(child),
)
Expand Down
12 changes: 7 additions & 5 deletions WDL/runtime/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,13 @@ def _eval_task_inputs(
# supplied None to override any default.
input_decls = task.available_inputs
posix_inputs = posix_inputs.filter(
lambda b: not (
isinstance(b.value, Value.Null)
and b.name in input_decls
and input_decls[b.name].expr
and not input_decls[b.name].type.optional
lambda b: (
not (
isinstance(b.value, Value.Null)
and b.name in input_decls
and input_decls[b.name].expr
and not input_decls[b.name].type.optional
)
)
)

Expand Down
12 changes: 7 additions & 5 deletions WDL/runtime/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,13 @@ def __init__(
# allow the supplied None to override any default.
input_decls = workflow.available_inputs
self.inputs = self.inputs.filter(
lambda b: not (
isinstance(b.value, Value.Null)
and b.name in input_decls
and input_decls[b.name].expr
and not input_decls[b.name].type.optional
lambda b: (
not (
isinstance(b.value, Value.Null)
and b.name in input_decls
and input_decls[b.name].expr
and not input_decls[b.name].type.optional
)
)
)

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ write_to = "WDL/_version.py"
mypy_path = "${MYPY_CONFIG_FILE_DIR}/stubs"

[tool.ruff]
line-length = 100
exclude = ["WDL/_version.py"]

[tool.ruff.lint]
ignore = ["E741", "E731"]
Loading