python / python/mypy

Infinite recursion in generate_c_type_stub when an a type's attr has the same name as its parent

Open
#11,989 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report

While trying out stubgen for the first time on a C(++)-extension module I get a 'RecursionError: maximum recursion depth exceeded' due to infinite recursion.

To Reproduce

conda create --name stubs python=3.9 --channel conda-forge --channel bioconda
conda install pyopenms mypy
stubgen -p pyopenms

Expected Behavior

No error. If I add a if (attr != class_name): here
https://github.com/python/mypy/blob/master/mypy/stubgenc.py#L361

it runs through.

BTW: You might also need to increase the timeout here: https://github.com/python/mypy/blob/master/mypy/moduleinspect.py#L165
No clue why it is so short.

Actual Behavior

Traceback (most recent call last):
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/site-packages/mypy/stubgenc.py", line 367, in generate_c_type_stub
    generate_c_type_stub(module, attr, value, types, imports=imports, sigs=sigs,
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/site-packages/mypy/stubgenc.py", line 367, in generate_c_type_stub
    generate_c_type_stub(module, attr, value, types, imports=imports, sigs=sigs,
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/site-packages/mypy/stubgenc.py", line 367, in generate_c_type_stub
    generate_c_type_stub(module, attr, value, types, imports=imports, sigs=sigs,
  [Previous line repeated 989 more times]
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/site-packages/mypy/stubgenc.py", line 356, in generate_c_type_stub
    generate_c_function_stub(module, attr, value, methods, imports=imports,
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/site-packages/mypy/stubgenc.py", line 182, in generate_c_function_stub
    inferred = infer_sig_from_docstring(docstr, name)
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/site-packages/mypy/stubdoc.py", line 232, in infer_sig_from_docstring
    for token in tokens:
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/tokenize.py", line 525, in _tokenize
    pseudomatch = _compile(PseudoToken).match(line, pos)
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/tokenize.py", line 99, in _compile
    return re.compile(expr, re.UNICODE)
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/re.py", line 292, in _compile
    flags = flags.value
  File "/Users/pfeuffer/miniconda3/envs/pyopenms_stubs/lib/python3.9/types.py", line 178, in __get__
    return self.fget(instance)
RecursionError: maximum recursion depth exceeded

Your Environment

  • Mypy version used: 0.931
  • Mypy command-line flags: -p pyopenms
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.9.9
  • Operating system and version: macOS 10.15.4

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 in mypy/stubgenc.py around generate_c_type_stub at the reported line, then reproduce with stubgen -p pyopenms using the listed environment. Trace how an attribute with the same name as its parent is handled; done means the command completes without RecursionError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.