Skip to content

Draft Idea For Pre Tasks To Be Context Aware #1041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aantillonl
Copy link

@aantillonl aantillonl commented Jun 30, 2025

This commit introduces a draft implementation of a mechanism that allows tasks designated as pre-tasks to retain information about their assignment via a _is_pre_of attribute.

When a Call object is created from a Task instance with this attribute set, the resulting Call will include a reference to the main task that declared the current task as a pre-task. This reference is made accessible during the pre-task's execution through the context passed to the task, allowing for greater introspection or conditional behavior based on the calling task.

The approach taken here favors composability and minimal intrusion into existing class implementations. It uses idiomatic Python patterns—such as generic decorators and lightweight descriptors—to introduce this functionality without tightly coupling it to the core Task or Call classes.

It’s possible that making tasks more stateful in this way—by tracking their assignment as pre-tasks—may not align with the long-term design philosophy of this library. If that's the case, I completely understand, and I'm happy to explore other areas where I could contribute to this great project.

There are a few issues in the CI pipeline, if this idea gets some push, I will address them promptly

ToDo

  • Lint
  • MyPy

@aantillonl aantillonl force-pushed the dev branch 2 times, most recently from 9570e22 to 2b2da60 Compare June 30, 2025 06:58
This commit introduces, in a draft state, the idea to allow tasks
that are called as a pre task for another task, to keep state
of this pre task assignment via the attribute `_is_pre_of`.

This attribute is later used when a `Call` object is created
from a `Task` instance that has said attribute set. A `Call`
created from a pre task, will add a reference to the task
that defines the current task as pre task, and said reference
will be available during the pre task's execution in the
context passed to the task.

The approach here suggested uses Pythonic patterns to avoid
changes to the class implementation as much as possible, but
rather compose the new functionality from invidivual, signle
purpose small components, such as a generic decorator, and
a descriptor component.

It can be very well the case that making a task more stateful
by tracking this pre assignment is not aligned with the design
if this library, in which case it would be better not to
add functionality that is not part of the long term view for
the library. I would be happy to contribute to this greaat
library in other ways.
@aantillonl aantillonl marked this pull request as draft July 10, 2025 17:01
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