Skip to content

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

Closed

Description

@erictraut

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.

Activity

  1. erictraut commented on Feb 5, 2022

    @erictraut
    ContributorAuthor

    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.

  2. srittau commented on Feb 5, 2022

    @srittau
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions