Skip to content

Fix handling of function from standard library#516

Merged
utf merged 1 commit intomaterialsproject:mainfrom
gpetretto:builtin
Jan 7, 2024
Merged

Fix handling of function from standard library#516
utf merged 1 commit intomaterialsproject:mainfrom
gpetretto:builtin

Conversation

@gpetretto
Copy link
Contributor

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
Copy link
Member

utf commented Jan 7, 2024

Thanks @gpetretto

@utf utf merged commit c60b8d0 into materialsproject:main Jan 7, 2024
@utf utf added the fix Bug fix label Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants