-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tune] Raise an error if Tuner.restore()
is called on an instance
#39676
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be TypeError
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 aTuner
object 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
Tuner
class 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.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.