Skip to content

fix stubgen crash on an extension module containing an alias of object #2910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2017

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Feb 27, 2017

Closes python/typeshed#766.

I verified that the new test case fails without the changes made in
stubgenc.py. Obviously a lot more tests for stubgenc could be added,
but that's for another day.

The original crash can be reproduced by creating file called alias.py
containing the line alias = object, compiling it to a .so with
Cython, and running stubgen on the .so. I got the following stack
trace:

$ python3 -m mypy.stubgen alias
Traceback (most recent call last):
  File ".../lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File ".../lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File ".../lib/python3.6/site-packages/mypy/stubgen.py", line 734, in <module>
    main()
  File ".../lib/python3.6/site-packages/mypy/stubgen.py", line 632, in main
    raise e
  File ".../lib/python3.6/site-packages/mypy/stubgen.py", line 629, in main
    interpreter=options.interpreter)
  File ".../lib/python3.6/site-packages/mypy/stubgen.py", line 101, in generate_stub_for_module
    class_sigs=class_sigs)
  File ".../lib/python3.6/site-packages/mypy/stubgenc.py", line 41, in generate_stub_for_c_module
    generate_c_type_stub(module, name, obj, types, sigs=sigs, class_sigs=class_sigs)
  File ".../lib/python3.6/site-packages/mypy/stubgenc.py", line 169, in generate_c_type_stub
    if all_bases[-1] is object:
IndexError: list index out of range

Closes python/typeshed#766.

I verified that the new test case fails without the changes made in
stubgenc.py. Obviously a lot more tests for stubgenc could be added,
but that's for another day.

The original crash can be reproduced by creating file called alias.py
containing the line `alias = object`, compiling it to a .so with
Cython, and running stubgen on the .so. I got the following stack
trace:

$ python3 -m mypy.stubgen alias
Traceback (most recent call last):
  File ".../lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File ".../lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File ".../lib/python3.6/site-packages/mypy/stubgen.py", line 734, in <module>
    main()
  File ".../lib/python3.6/site-packages/mypy/stubgen.py", line 632, in main
    raise e
  File ".../lib/python3.6/site-packages/mypy/stubgen.py", line 629, in main
    interpreter=options.interpreter)
  File ".../lib/python3.6/site-packages/mypy/stubgen.py", line 101, in generate_stub_for_module
    class_sigs=class_sigs)
  File ".../lib/python3.6/site-packages/mypy/stubgenc.py", line 41, in generate_stub_for_c_module
    generate_c_type_stub(module, name, obj, types, sigs=sigs, class_sigs=class_sigs)
  File ".../lib/python3.6/site-packages/mypy/stubgenc.py", line 169, in generate_c_type_stub
    if all_bases[-1] is object:
IndexError: list index out of range
@JukkaL
Copy link
Collaborator

JukkaL commented Feb 27, 2017

Thanks for the PR! Can you have a look at the CI failures?

@JelleZijlstra
Copy link
Member Author

Interesting, seems like it triggered a mypy bug where module and ModuleType aren't compatible. I'll report that separately and work around it here for now.

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 27, 2017

LGTM!

@JukkaL JukkaL merged commit b067c4f into python:master Feb 27, 2017
@JelleZijlstra JelleZijlstra deleted the stubgencrash branch May 4, 2017 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants