python / python/mypy

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

Offen
#19,181 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

documentation needs discussion topic-plugins
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit den verknüpften Hook-Docstrings in mypy/plugin.py um die Zeilen 647-648 und 664 und reproduziere anschließend das bereitgestellte Beispiel mit mypy.ini, plugin.py und test.py. Vergleiche den dokumentierten fullname mit dem beobachteten Wert test.Derived.method; die Arbeit ist abgeschlossen, wenn der Docstring das Hook-Argument korrekt erklärt oder das gemeldete Missverständnis aufgeklärt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
documentation
Issue-Typ
Dokumentation
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.