Skip to content

Regression: Cannot combine @property decorator with @abstractclassmethod #7134

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

Closed
erictraut opened this issue Feb 5, 2022 · 2 comments · Fixed by #9771
Closed

Regression: Cannot combine @property decorator with @abstractclassmethod #7134

erictraut opened this issue Feb 5, 2022 · 2 comments · Fixed by #9771

Comments

@erictraut
Copy link
Contributor

This commit changed the definition of abstractclassmethod and abstractstaticmethod in a way that makes them no longer callable. That means they cannot be used with other decorators (like property) that require a callable.

The following previously type checked without errors, but it no longer works.

    @property
    @abc.abstractclassmethod
    def foo(self) -> str: ...

The new declaration of abstractclassmethod and abstractstaticmethod also completely obscure the signature of the function they're decorating, which is a big problem for type checking (and completion suggestions, etc.).

I recommend reverting the change for abstractclassmethod and abstractstaticmethod. If there is a compelling reason to wrap these in a class, then the class should be parameterized with a ParamSpec and should include a __call__ method so it is still callable. @srittau, do you have a preference?

I won't be able to incorporate the latest typeshed stubs into pyright or pylance until this is addressed because this regression results in significant problems for internal Microsoft code bases.

@erictraut
Copy link
Contributor Author

Digging into this further, most of the uses of abstractclassmethod and abstractstaticmethod in our internal code base were inappropriate uses. These decorators are deprecated as of Python 3.2, so they shouldn't generally be used. But I think the recent change is still problematic.

@srittau
Copy link
Collaborator

srittau commented Feb 5, 2022

These problems seem to be inherited from classmethod/staticmethod, which are also lacking __call__ in the stubs, although they exist at runtime.

There was a PR previously that used ParamSpec, but it was abandoned since at that time mypy's ParamSpec-support was lacking.

I will send a PR later to resolve these issues.

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.

2 participants