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

Check for abstract base class definitions with no abstractmethods #273

Closed
Zac-HD opened this issue Aug 16, 2022 · 7 comments
Closed

Check for abstract base class definitions with no abstractmethods #273

Zac-HD opened this issue Aug 16, 2022 · 7 comments

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Aug 16, 2022

from abc import ABC, ABCMeta, abstractmethod

class Base(ABC):  # I'd like a lint error here if there are no @abstract* decorated methods

    # @abstractmethod
    def method(self):
        ...

class MyABC(metaclass=ABCMeta):  # and here too for the same reason
    pass

Suggested message: {classname} is an abstract base class, but it has no abstract methods. Remember to use @abstractmethod, @abstractclassmethod, and/or @abstractproperty decorators.

We might also want to emit a warning for a probably-missing-decorator on any method of an ABC where the whole method body is ..., even if there are some abstract-decorated methods on the class.

@cooperlees
Copy link
Collaborator

I can't see how this could draw false positives ... so can do nothing but help. I feel this fits things bugbear looks for ... PR will be accepted.

@jakkdl
Copy link
Contributor

jakkdl commented Aug 17, 2022

I'm starting on a PR now!

We might also want to emit a warning for a probably-missing-decorator on any method of an ABC where the whole method body is ..., even if there are some abstract-decorated methods on the class.

How about extending this to the body being anything but pass, ... or string constants - to also catch

# @abstractmethod
def method(self):
  """my abstract method"""
  pass

Similar to pyright's check for @overload with an implementation https://github.com/microsoft/pyright/blob/6fa755c025cb5b18838d8bfdd85761184afa45f1/packages/pyright-internal/src/analyzer/parseTreeUtils.ts#L1999

@Zac-HD
Copy link
Member Author

Zac-HD commented Aug 18, 2022

Closed by #274.

@Zac-HD Zac-HD closed this as completed Aug 18, 2022
@jakkdl
Copy link
Contributor

jakkdl commented Aug 22, 2022

If you also want

We might also want to emit a warning for a probably-missing-decorator on any method of an ABC where the whole method body is ..., even if there are some abstract-decorated methods on the class.

you can open a separate issue for it, should be an easy one as well :)

@cooperlees
Copy link
Collaborator

I'm easy - I was going to release a new version today - Should we wait for this?

@Zac-HD
Copy link
Member Author

Zac-HD commented Aug 22, 2022

Nah, let's release what we've got now and let future features take care of themselves.

(though Cooper, you might want to copy the auto release set up from flake8-async to make releases really easy in future?)

@cooperlees
Copy link
Collaborator

I'm not a fan of that tbh as we don't have good enough change log enforcement etc. with this project so the 1 commit + release via GitHub is there enough for me imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants