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

classmethods should not be able to be called on abstract classes #14062

Closed
DetachHead opened this issue Nov 11, 2022 · 2 comments
Closed

classmethods should not be able to be called on abstract classes #14062

DetachHead opened this issue Nov 11, 2022 · 2 comments
Labels

Comments

@DetachHead
Copy link
Contributor

DetachHead commented Nov 11, 2022

from abc import ABC, abstractmethod

class Foo(ABC):
    @classmethod
    def foo(cls) -> Foo:
        return cls()
    
    @abstractmethod
    def bar(self) -> None:
        ...

Foo.foo() # no error

playground

most of the time, classmethods are instantiating the class, so it should not allow you to call them on abstract classes.

i do however think staticmethods should still be allowed as they do not have access to the cls

@JelleZijlstra
Copy link
Member

Classmethods can do other things than instantiating a class. I think this check would be too noisy to be useful.

@erictraut
Copy link

I agree that this would be too noisy. Recommend closing.

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

No branches or pull requests

3 participants