Skip to content
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 - custom metaclass derived from ABCMeta treated as abstract base class #280

Closed
antonymayi opened this issue Aug 29, 2022 · 2 comments · Fixed by #281
Closed

Comments

@antonymayi
Copy link

Another false positive with the recent B024 is when implementing custom metaclass extended from ABCMeta - they shouldn't be classified as abstract base classes at all:

class MyMeta(abc.ABCMeta):  # THIS GETS FALSE POSITIVE B024 BUT IS PERFECTLY LEGIT
    def __new__(mcs, name, bases, namespace):
        #  whatever custom metaclass magic here
        return super().__new__(mcs, name, bases, namespace)

class MyAbstract(metaclass=MyMeta):
    @abstractmethod
    def foobar(self):
        pass
B024 MyMeta is an abstract base class, but it has no abstract methods. Remember to use @abstractmethod, @abstractclassmethod and/or @abstractproperty decorators.
class MyMeta(abc.ABCMeta):

-> MyMeta is actually not an abstract base class (instead, it is a custom metaclass for creating abstract base classes) so this is false positive.

@jakkdl
Copy link
Contributor

jakkdl commented Aug 31, 2022

Hmm, should one maybe disable b024 for ABCMeta and only do it with ABC?
@Zac-HD

@Zac-HD
Copy link
Member

Zac-HD commented Aug 31, 2022

Ah, we should only warn on ABCMeta when it's a keyword argument (with metaclass=), and for ABC when that's a positional argument. is_abc_class() is currently a bit too broad.

jakkdl added a commit to jakkdl/flake8-bugbear that referenced this issue Sep 29, 2022
jakkdl added a commit to jakkdl/flake8-bugbear that referenced this issue Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants