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

no error when calling abstract staticmethod/classmethod #14939

Open
DetachHead opened this issue Mar 23, 2023 · 7 comments
Open

no error when calling abstract staticmethod/classmethod #14939

DetachHead opened this issue Mar 23, 2023 · 7 comments
Labels
bug mypy got something wrong good-second-issue

Comments

@DetachHead
Copy link
Contributor

from abc import ABC, abstractmethod

class Foo(ABC):
    @staticmethod
    @abstractmethod
    def foo() -> Foo:
        ...


Foo.foo() # no error

playground

@DetachHead DetachHead added the bug mypy got something wrong label Mar 23, 2023
@JukkaL
Copy link
Collaborator

JukkaL commented Apr 20, 2023

Note that the error is currently only generated when constructing an instance, since when calling a method on an instance, the runtime object could be an instance of a subclass with the method implemented.

We'd need to add add a new check when accessing an abstract static method (possibly also class method) of a direct reference to a type object, but not when using type[T], since again we might have an instance of a subclass. I think that a direct reference has a type CallableType, whereas type[T] has type TypeType.

@madt2709
Copy link
Contributor

Hi, I was looking into picking this up but was unsure where was the best place in the code to put this in. I have created a test to reproduce and the bug still exists. Should this be a separate check within checkexpr.py (particularly in the check_callable_call) or should it be within the checker.py file or somewhere completely different?

erictraut pushed a commit to microsoft/pyright that referenced this issue May 13, 2023
@erictraut
Copy link

This is (largely) a duplicate of #14939. As Jukka says, the current behavior is to report the problem when an abstract class is instantiated. This mirrors the error seen at runtime. And as discussed in the duplicate issue, there's a good reason not to emit an error when a class method or static method is called here. Recommend closing.

@JelleZijlstra
Copy link
Member

#14939 is this issue, which one were you thinking of?

@erictraut
Copy link

Oops, I meant #14062.

@JelleZijlstra
Copy link
Member

Thanks, I feel this one different and more reasonable as a feature request, as here the ask is to warn about calls to abstract static/classmethods, while #14062 wanted a warning for calls to non-abstract static/classmethods on abstract classes. Jukka's comment above explains how such a check could be implemented.

@keshavt3
Copy link

keshavt3 commented Apr 3, 2024

I want to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong good-second-issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants