python / python/mypy

Stubgen creates instance methods instead of class variables for C extensions

Open
#14,116 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-stubgen
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

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

Reproduce the issue with the provided PyICU build commands and inspect the stubgen path that classifies members from C extensions. Confirm the generated icu.pyi output for URegionType, then add coverage or a fix so CONTINENT and the other enumeration members are emitted as class variables rather than methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.