Skip to content

set_working_tape switches on annotation#245

Draft
JHopeCollins wants to merge 1 commit intomasterfrom
JHopeCollins/set_working_tape-annotations
Draft

set_working_tape switches on annotation#245
JHopeCollins wants to merge 1 commit intomasterfrom
JHopeCollins/set_working_tape-annotations

Conversation

@JHopeCollins
Copy link
Contributor

@JHopeCollins JHopeCollins commented Feb 6, 2026

If annotations are switched off and you use the set_working_tape context manager then nothing gets taped, which can be confusing and/or inconvenient in some circumstances (e.g. if you are inside some function/library and annotation was switched off above you in the stack).

We're also trying to move to set_working_tape being the best-practice to limit the scope of each tape, so you end up writing things like:

was_annotating = annotate_tape()
continue_annotation()
with set_working_tape() as tape:
	...
if not was_annotating:
	pause_annotation()

This PR makes set_working_tape do the logic to a) make sure we have annotations on inside the context manager and b) return the annotation state to the value before the context manager. The above code just becomes:

with set_working_tape() as tape:
	...

The previous behaviour can be obtained by setting the continue_annotations kwarg

with set_working_tape(continue_annotations=False) as tape:
	...

@connorjward
Copy link
Contributor

Is this the right approach? I would expect that if I have some code like

with stop_annotating():
    do_something()

Then taping should always be disabled in do_something().

@JHopeCollins
Copy link
Contributor Author

JHopeCollins commented Feb 6, 2026

Is this the right approach? I would expect that if I have some code like

with stop_annotating():
    do_something()

Then taping should always be disabled in do_something().

You can get that with set_working_tape(continue_annotation=False). Setting the default to True is a somewhat opinionated personal preference, I wouldn't be totally averse to changing the default to False to avoid this being an API breaking change.

I'd also say that stop_annotating arguably is implicitly saying "stop annotating the current working tape", so it is questionable if it should always be propogated if the tape changes.

@connorjward
Copy link
Contributor

I feel like it makes sense to decouple the notions of which tape is the active one and whether taping is enabled, but that's just me.

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.

2 participants