Skip to content

Commit 96864ba

Browse files
committed
Fix.
1 parent ea71f03 commit 96864ba

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/_pytask/_inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_annotations(
4545
versions without :mod:`annotationlib` - we fall back to the stdlib implementation,
4646
so behaviour on 3.10-3.13 remains unchanged.
4747
"""
48-
if sys.version_info < (3, 14):
48+
if sys.version_info < (3, 14) or not eval_str or not hasattr(obj, "__globals__"):
4949
return _get_annotations_from_inspect(
5050
obj, globals=globals, locals=locals, eval_str=eval_str
5151
)

src/_pytask/task_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,15 @@ def parse_keyword_arguments_from_signature_defaults(
310310

311311
def _snapshot_annotation_locals(func: Callable[..., Any]) -> dict[str, Any] | None:
312312
"""Capture the values of free variables at decoration time for annotations."""
313-
if func.__closure__ is None:
313+
while isinstance(func, functools.partial):
314+
func = func.func
315+
316+
closure = getattr(func, "__closure__", None)
317+
if not closure:
314318
return None
315319

316320
snapshot = {}
317-
for name, cell in zip(func.__code__.co_freevars, func.__closure__, strict=False):
321+
for name, cell in zip(func.__code__.co_freevars, closure, strict=False):
318322
with suppress(ValueError):
319323
snapshot[name] = cell.cell_contents
320324

0 commit comments

Comments
 (0)