python / python/mypy

Add a plugin hook for handling function/method decorators

Open
#9,915 0 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature topic-plugins
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature

mypy currently has the get_class_decorator_hook plugin hook. I want to propose adding a get_function_decorator_hook and get_method_decorator_hook.

Pitch

Adding these hooks would allow special handling of decorated functions, as would for example be required to solve #9911 using a plugin. mypy currently has special handling for a few decorated such as builtins.property, typing.final and more, but from what I can see it's currently not possible to add additional cases using a plugin.

I have already experimented with this a bit and could probably open a PR in the near future.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing mypy's existing get_class_decorator_hook plugin hook and the handling of decorated functions, including builtins.property and typing.final. Define the corresponding function and method decorator hooks so plugins can handle additional decorated cases, then verify that the hooks support the intended use case described in issue #9911.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.