[tune] Raise an error if Tuner.restore() is called on an instance#39676
Conversation
Signed-off-by: Kai Fricke <kai@anyscale.com>
| def __getattribute__(self, item): | ||
| if item == "restore": |
There was a problem hiding this comment.
I wish there was a cleaner way to do this directly in the definition of restore, but I'm not sure if there is one...
There was a problem hiding this comment.
I don't think so, at least I can't think of one right now. The @classmethod decorator passes the class in both cases...
|
|
||
| def __getattribute__(self, item): | ||
| if item == "restore": | ||
| raise AttributeError( |
There was a problem hiding this comment.
Should this be TypeError instead?
There was a problem hiding this comment.
From https://docs.python.org/3/library/exceptions.html#AttributeError
exception AttributeError
Raised when an attribute reference (see Attribute references) or assignment fails. (When an object does not support attribute references or attribute assignments at all, TypeError is raised.)
And
https://docs.python.org/3/reference/expressions.html#attribute-references
If this attribute is not available, the exception AttributeError is raised.
I think AttributeError is correct. Tuner generally supports attribute references, but not this one. It's supposed to be like "this attribute does not exist for an instance (only for the class)"
…ay-project#39676) `Tuner.restore()` is used to construct a `Tuner` object from an existing experiment. However, calling `tuner = Tuner(...); tuner.restore()` is a common misuse of the API and does not throw an error. This PR updates the `Tuner` class to only allow `restore()` to be called on the class, not on an instance of the class. Signed-off-by: Kai Fricke <kai@anyscale.com> Signed-off-by: Victor <vctr.y.m@example.com>
Why are these changes needed?
Tuner.restore()is used to construct aTunerobject from an existing experiment. However, callingtuner = Tuner(...); tuner.restore()is a common misuse of the API and does not throw an error.This PR updates the
Tunerclass to only allowrestore()to be called on the class, not on an instance of the class.Related issue number
Closes #39674
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.