materialsproject / jobflow

jobflow is a library for writing computational workflows.
https://materialsproject.github.io/jobflow
Other
93 stars 24 forks source link

Fix handling of function from standard library #516

Closed gpetretto closed 9 months ago

gpetretto commented 9 months ago

Summary

I was trying to use a function from the standard library to create a simple example and I got an error:

import time
from jobflow import Job, SETTINGS

j = Job(time.sleep, (1,))
j.run(SETTINGS.JOB_STORE)

gives

TypeError: time.sleep() takes exactly one argument (2 given)

The reason is that sleep has a __self__ attribute and in Job it is then converted to a bound method. This seems to be shared by most (all?) the functions in the standard library.

To adress this I changed the check performed in Job.run() assuming that if the __self__ is a module, than the callable should not be converted to a method. I am not entirely sure if I may be missing some case where this is not true.

utf commented 9 months ago

Thanks @gpetretto