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
False positive B024 #278
Comments
flake8-bugber has recently released a new version: 22.8.22 where a new lint error checking that an ABC should always have abstractmethods was introduced. This is however not necessarily a pythonic way of using ABCs as they do provide some other functionalities than just abstractmethods (see: PyCQA/flake8-bugbear#278). For this reason, I don't think we should respect this bugbear error, and it can be ignored, as it might potentially even get removed from bugbear completely at some point.
Also, ABC could just be there to declare a class variable that should be set for concrete classes in a less verbose way than using annotations and properties: class Abstract(ABC):
attr: ClassVar[str] This is checked by mypy and will also raise an |
This is how it's used in our project too: https://github.com/rotki/rotki/blob/2c2bc209ba1d51663a86f4b710dfa6bbc24e7535/rotkehlchen/data_import/importers/binance.py#L43-L97 I don't think this is a good check to have and would opt to remove it. |
Also got false positive for this case:
|
Hey! What's the reason the issue is closed? Is it done on purpose (essentially, "wontfix"), or is it a side-effect of some commit message? |
The comments above indicate a fix was landed (via #281). If you believe the latest version still does hi-lights this issue incorrectly still we can reopen this issue. A repro, example code (if it differs in any way) or suggestions on how to make this better always welcome. |
I think that the whole B024 should at least be optional. It's not an issue with the implementation, but rather with the idea: that's not a mistake to use an abstract class without abstract methods. There are examples in official Python docs, as well as in real-world projects; both are linked in the ticket description. |
This was closed because it now shouldn't warn for classes that inherits from multiple classes (as is the case in https://github.com/scrapinghub/web-poet/blob/944dcd75f6c56988d42c56c56adb1b3dcafa2dbd/web_poet/pages.py#L11 ) and is also silenced by having any attr's (as #278 (comment) ). So your project, at least in that case, should not be raising B024. https://docs.python.org/3/library/abc.html#abc.ABCMeta.register will still raise a warning, and I suppose that classes that are empty (only contains docstrings, pass and/or But the error message is explicitly just a suggestion
as it isn't a definite error, though maybe one could word it even slighter. |
Oh actually, the error message differs from the one written in the readme, and sounds more certain. Will fix that
|
Hey! A new release (with #273 included) raises an error
I think that's fine to use ABC without abstractmethods/etc., because that's not the only thing ABCs do. They also allow to register other classes as being subclasses of the base class - see example at https://docs.python.org/3/library/abc.html#abc.ABCMeta.register.
This is how ABC is used in our project (see https://github.com/scrapinghub/web-poet/blob/944dcd75f6c56988d42c56c56adb1b3dcafa2dbd/web_poet/pages.py#L11); a new flake8-bugbear release flags it as an error.
The text was updated successfully, but these errors were encountered: