-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Refactor]Fix ruff rule B024: abstract-base-class-without-abstract-method(setting) #49917
base: master
Are you sure you want to change the base?
[Refactor]Fix ruff rule B024: abstract-base-class-without-abstract-method(setting) #49917
Conversation
0ba9171
to
cd42eb8
Compare
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.
simply removing ABC
is unlikely to be the right fix for most of these cases. The right fix is more likely to be adding @abstractmethod
for methods that are abstract.
from typing import List, Union | ||
|
||
import torch | ||
|
||
|
||
class TorchDeviceManager(ABC): | ||
class TorchDeviceManager: |
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 am not very familiar with this part of the code, but these fixes are unlikely the right fix.
reading the code, it is pretty clear that this class is an interface class. the right fix is more likely to be declaring all the methods as @abstractmethod
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.
Hi @aslonnie, I tried adding @abstractmethod
, but the tests failed because it raises an error if child classes don't implement the method.
So, simply adding @abstractmethod
to methods with NotImplementedError
won't work.
That said, I understand your point about maintaining the abstract structure.
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.
In this case, you should annotate all methods in TorchDeviceManager
with @abstractmethod
. Then, for all classes inheriting from it, such as CPUTorchDeviceManager
, if any methods from TorchDeviceManager
are not implemented, provide an implementation with a method body that raises NotImplementedError
.
Looks like this:
class TorchDeviceManager(ABC):
@abstractmethod
def get_current_stream(self):
"""Get current stream on accelerators like torch.cuda.current_stream"""
...
class CPUTorchDeviceManager(TorchDeviceManager):
def get_current_stream(self):
raise NotImplementedError
e9c3c23
to
3efec3b
Compare
Let's divide this PR into several smaller PRs for easier review and debugging in CI. Refer to the Ruff settings for details: |
3efec3b
to
72b20be
Compare
Signed-off-by: SimoTw <[email protected]>
72b20be
to
8366487
Compare
Good idea. |
Why are these changes needed?
according to the abstract-base-class-without-abstract-method rule
According to the discussion below.
This PR is design to be the setting to divide the task into several small PRs.
Related issue number
#47991
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.