Skip to content

Commit

Permalink
ENH Support lambdas in Tasklets
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Feb 22, 2024
1 parent ab737fd commit ef66785
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,3 +1,6 @@
Unreleased
* Support for lambda functions in Tasklets

Version 2.3.1 Sun 5 November 2023 by luispedro
* jug: update for Python 3.12

Expand Down
3 changes: 3 additions & 0 deletions docs/source/tasklets.rst
Expand Up @@ -4,6 +4,9 @@ Tasklets
.. versionadded:: 0.8
Tasklets were added in version 0.8, starting with the betas (named 0.7.9..)

.. versionchanged:: 2.4.0
Since version 2.4.0, Tasklets can use a lambda function

A Tasklet is a light-weight task. It looks very similar to a Task *except that
it does not save its results to disk*. Every time you need its output, it is
recomputed. Other than that, you can pass it around, just like a Task.
Expand Down
4 changes: 2 additions & 2 deletions jug/task.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2008-2021, Luis Pedro Coelho <luis@luispedro.org>
# Copyright (C) 2008-2024, Luis Pedro Coelho <luis@luispedro.org>
# vim: set ts=4 sts=4 sw=4 expandtab smartindent:
# LICENSE: MIT
'''
Expand Down Expand Up @@ -440,7 +440,7 @@ def __jug_hash__(self):
M.update(b'Tasklet')
hash_update(M, [
('base', self.base),
('f', self.f),
('f', self.f if getattr(self.f, '__name__', '') != '<lambda>' else ('<lambda>', self.f.__code__.co_code))
])
return M.hexdigest().encode('utf-8')

Expand Down
2 changes: 2 additions & 0 deletions jug/tests/jugfiles/tasklets.py
Expand Up @@ -15,4 +15,6 @@ def plus1(x):
t2 = t[2]
t0_2 = Task(sum2, t0, t2)
t0_2_1 = Tasklet(t0_2, plus1)
t0_2_2 = Tasklet(t0_2_1, lambda x: x + 1)

final = Task(sum2, t0_2_1, t0_2_2)

0 comments on commit ef66785

Please sign in to comment.