python / python/mypy

Wording in `mypy.plugin.Plugin.get_method[_signature]_hook` docstring

Open
#19,181 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation needs discussion topic-plugins
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Documentation

The docstring of these plugin hook methods currently say:

https://github.com/python/mypy/blob/057508b4cb405fbc22e26b44f764b142352fcce5/mypy/plugin.py#L647-L648

...

https://github.com/python/mypy/blob/057508b4cb405fbc22e26b44f764b142352fcce5/mypy/plugin.py#L664

I understand this to mean that the argument to fullname will be "__main__.Base.method", because __main__.Base defines method.

However, this doesn't seem to be the case. Setting up the same example in the docstring:

  • mypy.ini
    [mypy]
    plugins = plugin.py
    files = test.py
    
  • plugin.py
    from mypy.plugin import Plugin
    
    def plugin(version):
        return TestPlugin
    
    class TestPlugin(Plugin):
        def get_method_signature_hook(self, fullname):
            if fullname.startswith("test."):
                print(f"Hook will be called with `{fullname}`")
    
  • test.py
    from typing import Any
    
    class Base:
        def method(self, arg: Any) -> Any: ...
    
    class Derived(Base): ...
    
    var: Derived
    var.method(42)
    
$ mypy
Hook will be called with `test.Derived.method`

I installed as far back as mypy 0.9x and it was the same behaviour as described above, displaying test.Derived.method (not test.Base.method).


Is there something wrong with the docstring (perhaps from outdated behaviour that no longer applies), or have I misunderstood something?

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 with the linked hook docstrings in mypy/plugin.py around lines 647-648 and 664, then reproduce the supplied mypy.ini, plugin.py, and test.py example. Compare the documented fullname with the observed test.Derived.method value; the work is done when the docstring accurately explains the hook argument or the reported misunderstanding.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.