Skip to content

fix: preserve definition locals for postponed task annotations - #1026

Merged
tobiasraabe merged 7 commits into
mainfrom
codex/postponed-annotation-snapshots
Oct 17, 2026
Merged

tobiasraabe merged 7 commits into
mainfrom
codex/postponed-annotation-snapshots

Conversation

@tobiasraabe

@tobiasraabe tobiasraabe commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Nested tasks defined with from __future__ import annotations lost the enclosing function's local bindings before collection. Generated tasks whose product path existed only in an annotation therefore failed with NameError or could resolve against the final loop value.

Capture a separate shallow definition-local snapshot for each decorated task, including future annotations. Referenced objects remain shared; module-level future annotations continue to use current globals, and native module-level loop behavior is preserved. Release snapshots after collection and its modification hooks finish, including generated-child collection, collection-hook failures, and children registered before a generator body raises. Internal registration through the programmatic interface and after= does not retain pytask's own locals as the task's annotation namespace.

Regression tests cover per-task outputs, shallow sharing, plugin access during collection, programmatic registration, snapshot release, and pickling. Generator-body failure tests verify cleanup after RuntimeError and SystemExit, preservation of the original exception, and pickling of retained children with an unrelated generator-local lock. Six after= cases exercise global names colliding with internal locals under native and future annotations. The generator notebook asserts copied contents, and workflow filters accept slash-containing base branches.

Validation:

  • 146 annotation, collection, generator, and decorator tests passed on Python 3.13 and 3.14.
  • All six new after= cases failed on Python 3.14 before the fix.
  • All four generator-body failure cases failed on Python 3.14 before the cleanup fix.
  • just lint and just typing passed.

Follow-up work: annotation resolution when task callables are reused or later hooks revisit previously collected tasks. Broader transactional expansion and continued execution remain separate work under #985.

Follows #1025, which is now merged into main.

@tobiasraabe
tobiasraabe added this pull request to stack #1027 October 14, 2026 04:27
@tobiasraabe
tobiasraabe force-pushed the codex/postponed-annotation-snapshots branch from f895e84 to 858157f Compare October 17, 2026 08:56
@tobiasraabe tobiasraabe changed the title Snapshot definition locals for postponed task annotations fix: preserve definition locals for postponed task annotations Oct 17, 2026
@tobiasraabe
tobiasraabe force-pushed the codex/postponed-annotation-snapshots branch from 1a3d716 to 94c335c Compare October 17, 2026 09:18
@tobiasraabe
tobiasraabe marked this pull request as ready for review October 17, 2026 09:18
Base automatically changed from codex/annotation-namespaces to main October 17, 2026 09:30
@tobiasraabe
tobiasraabe force-pushed the codex/postponed-annotation-snapshots branch from 94c335c to c799064 Compare October 17, 2026 09:30
@tobiasraabe
tobiasraabe added this pull request to the merge queue Oct 17, 2026
Merged via the queue into main with commit 9559bb0 Oct 17, 2026
32 of 33 checks passed
@tobiasraabe
tobiasraabe deleted the codex/postponed-annotation-snapshots branch October 17, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant