python / python/mypy

Stubgen creates instance methods instead of class variables for C extensions

Offen
#14,116 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-stubgen
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug Report

We are in the process of adding .pyi stubs for PyICU. (https://gitlab.pyicu.org/)

The URegionType class, for example, is an enumeration. inspect.getmembers(icu.URegionType) lists [('CONTINENT', 3), ('DEPRECATED', 6), ('GROUPING', 5), ('SUBCONTINENT', 4), ('TERRITORY', 1), ('UNKNOWN', 0), ('WORLD', 2), ('__class__', <class 'type'>), ('__delattr__', <slot wrapper '__delattr__' of 'object' objects>), ...

CONTINENT and other class variables are generated in _icu_.pyi as if they were class methods.

To Reproduce

The problem might be specific to C extensions. If you want to recreate the problem on the PyICU code:

python setup.py build
cd build/lib.linux-x86_64-cpython-310
stubgen -p icu

Expected Behavior

_icu_.pyi should have contained

class URegionType:
    CONTINENT: Any
    DEPRECATED: Any
    GROUPING: Any
    SUBCONTINENT: Any
    TERRITORY: Any
    UNKNOWN: Any
    WORLD: Any

Actual Behavior

_icu_.pyi instead contains:

class URegionType:
    def CONTINENT(self, *args, **kwargs) -> Any: ...
    def DEPRECATED(self, *args, **kwargs) -> Any: ...
    def GROUPING(self, *args, **kwargs) -> Any: ...
    def SUBCONTINENT(self, *args, **kwargs) -> Any: ...
    def TERRITORY(self, *args, **kwargs) -> Any: ...
    def UNKNOWN(self, *args, **kwargs) -> Any: ...
    def WORLD(self, *args, **kwargs) -> Any: ...

Your Environment

  • Mypy version used: 0.990
  • Mypy configuration options from mypy.ini (and other config files): defaults/none
  • Python version used: 3.10

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

Reproduziere das Problem mit den bereitgestellten PyICU-Build-Befehlen und untersuche den stubgen-Pfad, der Member aus C-Erweiterungen klassifiziert. Bestätige die generierte icu.pyi-Ausgabe für URegionType und füge anschließend Coverage oder eine Korrektur hinzu, sodass CONTINENT und die anderen Enumerationsmember als Klassenvariablen statt als Methoden ausgegeben werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

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