PLAMS icon indicating copy to clipboard operation
PLAMS copied to clipboard

BUG: Do not restrict static-/classmethods in `Results`

Open BvB93 opened this issue 3 years ago • 0 comments

Python 3.10 newly add the __call__ method to class- and staticmethods (xref bpo-43682), which has had some unforeseen consequences for the Result._replace_job_name static method (i.e. raising whenever a job is renamed).

The metaclass of Result wraps most of the its methods in a decorator that handles a few tasks such as ensuring thread-safety, writing to the logger, checking result statuses, etc.. Importantly, the decorators' signature assumes that it is a normal method that is being wrapped. Enter python 3.10: staticmethods are now also callables and hence Result._replace_job_name is now also all of a sudden being wrapped:

  File "/scistor/tc/kdf400/CAT/CAT/jobs.py", line 378, in job_geometry_opt
    results = job.run()
  File "/scistor/tc/kdf400/.conda/envs/CAT/lib/python3.10/site-packages/scm/plams/core/basejob.py", line 115, in run
    jobrunner._run_job(self, jobmanager)
  File "/scistor/tc/kdf400/.conda/envs/CAT/lib/python3.10/site-packages/scm/plams/core/jobrunner.py", line 28, in wrapper
    func(self, *args, **kwargs)
  File "/scistor/tc/kdf400/.conda/envs/CAT/lib/python3.10/site-packages/scm/plams/core/jobrunner.py", line 112, in _run_job
    if job._prepare(jobmanager):
  File "/scistor/tc/kdf400/.conda/envs/CAT/lib/python3.10/site-packages/scm/plams/core/basejob.py", line 194, in _prepare
    prev.results._copy_to(self.results)
  File "/scistor/tc/kdf400/.conda/envs/CAT/lib/python3.10/site-packages/scm/plams/core/results.py", line 65, in guardian
    return func(self, *args, **kwargs)
  File "/scistor/tc/kdf400/.conda/envs/CAT/lib/python3.10/site-packages/scm/plams/core/results.py", line 374, in _copy_to
    newname = Results._replace_job_name(name, self.job.name, newresults.job.name)
  File "/scistor/tc/kdf400/.conda/envs/CAT/lib/python3.10/site-packages/scm/plams/core/results.py", line 61, in guardian
    if not self.job:
AttributeError: 'str' object has no attribute 'job'

BvB93 avatar Mar 18 '22 12:03 BvB93