Skip to content

Commit 1dda71a

Browse files
committed
Fix ty 0.0.17 typing regressions
1 parent 43265ff commit 1dda71a

4 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/_pytask/coiled_utils.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,30 @@ class Function:
2222
__all__ = ["Function"]
2323

2424

25+
_MISSING = object()
26+
27+
28+
def _get_coiled_attribute(func: Function, *names: str, default: Any = _MISSING) -> Any:
29+
"""Get an attribute from coiled function objects with private/public fallbacks."""
30+
for name in names:
31+
value = getattr(func, name, _MISSING)
32+
if value is not _MISSING:
33+
return value
34+
if default is not _MISSING:
35+
return default
36+
names_as_text = ", ".join(repr(name) for name in names)
37+
msg = f"Cannot find coiled attribute(s) {names_as_text} on {func!r}."
38+
raise AttributeError(msg)
39+
40+
2541
def extract_coiled_function_kwargs(func: Function) -> dict[str, Any]:
2642
"""Extract the kwargs for a coiled function."""
2743
return {
28-
"cluster_kwargs": func._cluster_kwargs, # ty: ignore[possibly-missing-attribute]
44+
"cluster_kwargs": _get_coiled_attribute(
45+
func, "_cluster_kwargs", "cluster_kwargs"
46+
),
2947
"keepalive": func.keepalive,
30-
"environ": func._environ, # ty: ignore[possibly-missing-attribute]
31-
"local": func._local, # ty: ignore[possibly-missing-attribute]
32-
"name": func._name, # ty: ignore[possibly-missing-attribute]
48+
"environ": _get_coiled_attribute(func, "_environ", "environ"),
49+
"local": _get_coiled_attribute(func, "_local", "local", default=None),
50+
"name": _get_coiled_attribute(func, "_name", "name", default=None),
3351
}

src/_pytask/path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,10 @@ def _import_module_using_spec(
331331
break
332332
else:
333333
spec = importlib.util.spec_from_file_location(module_name, str(module_path))
334-
if spec is not None:
334+
if spec is not None and spec.loader is not None:
335335
mod = importlib.util.module_from_spec(spec)
336336
sys.modules[module_name] = mod
337-
spec.loader.exec_module(mod) # ty: ignore[possibly-missing-attribute]
337+
spec.loader.exec_module(mod)
338338
_insert_missing_modules(sys.modules, module_name)
339339
return mod
340340

src/_pytask/task_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def wrapper(func: T) -> TaskDecorated[T]:
186186

187187
# When decorator is used without parentheses, call wrapper directly.
188188
if is_task_function(name) and kwargs is None:
189-
return wrapper(cast("T", name))
189+
return wrapper(cast("T", name)) # ty: ignore[invalid-argument-type]
190190
return wrapper
191191

192192

tests/test_collect.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from _pytask.collect import _find_shortest_uniquely_identifiable_name_for_tasks
1212
from _pytask.collect import pytask_collect_node
13+
from _pytask.node_protocols import PPathNode
1314
from pytask import CollectionOutcome
1415
from pytask import ExitCode
1516
from pytask import NodeInfo
@@ -237,6 +238,7 @@ def test_pytask_collect_node_does_not_raise_error_if_path_is_not_normalized(
237238
)
238239
assert not record
239240

241+
assert isinstance(result, PPathNode)
240242
assert str(result.path) == str(real_node)
241243

242244

0 commit comments

Comments
 (0)