Skip to content
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

[stubgen] Crash on boost::python C extension #9888

Closed
Arpafaucon opened this issue Jan 7, 2021 · 2 comments · Fixed by #9889
Closed

[stubgen] Crash on boost::python C extension #9888

Arpafaucon opened this issue Jan 7, 2021 · 2 comments · Fixed by #9889
Labels

Comments

@Arpafaucon
Copy link

Arpafaucon commented Jan 7, 2021

Hey team ! First of all, happy new year, and thanks for your great work !

Crash Report

When running stubgen on a compiled python module using boost::python, stubgen crashes.

See below for a minimal reproducible example.

Traceback

Traceback (most recent call last):
  File "/install/bin/stubgen", line 8, in <module>
    sys.exit(main())
  File "mypy/stubgen.py", line 1564, in main
  File "mypy/stubgen.py", line 1457, in generate_stubs
  File "mypy/stubgenc.py", line 64, in generate_stub_for_c_module
  File "mypy/stubgenc.py", line 293, in generate_c_type_stub
  File "mypy/stubgenc.py", line 164, in generate_c_function_stub
TypeError: str object expected; got None

To Reproduce

I was able to break down a minimal example that breaks (thanks to TNG/boost_python_examples ). You find in the archive a sample C++ file and a basic CMakeLists to compile it

example.tar.gz

After extracting both files into a folder, build the library (requires python and libboost-python-dev)

mkdir build && cd build
cmake ..
make

Run stubgen on the generated lib
, sh

stubgen -p example_pywrap --search-path .

...and it crashes

Your Environment

  • Mypy version used: 0.790
  • Stubgen command-line flags:
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.8
  • Operating system and version: Ubuntu 20.04

Remarks

This closely looks like the bug fixed in #8888. And indeed, if I install the mypy build mentionned in this PR, the problem is fixed. (see this message: #8888 (comment))

  • stubgen does not crash
  • the output file out/example_pywrap.pyi exists and contains valid content

What I don't understand is that the PR has been merged 6 months ago, the resulting commit seems to be in the 0.790 tag (see commit ea9291d), so I should not see the crash on mypy 0.790, shoud I ?

[EDIT] I tested again with the latest master commit of this repo (mypy-0.800+dev.5f5d90eee23b809185145f6da7b18a3ca41b4879) and it works (no crashes). So:

  • If the crash was indeed fixed by Fix type expected by stubgenc #8888, can someone explain me why it was not in v0.790 even if the commit view mentions it ?
    image
  • Otherwise, I faced a different bug that was fixed after v0.790.

Either way, is there somewhere I can go to see the ETA for 0.800, so I can know if I need how long my work-around is supposed to hold.

hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this issue Jan 7, 2021
Fixes python#9888

I applied the following patch to typeshed and ran self check:
```
+@overload
+def getattr(__o: Any, name: str, __default: None) -> Optional[Any]: ...
+@overload
 def getattr(__o: Any, name: str, __default: Any = ...) -> Any: ...
 ```
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jan 7, 2021

Thanks for the report, opened #9889 to fix this.

The thing that's causing confusion for you is that the TypeError is raised by mypyc and so doesn't manifest if you don't compile mypy with mypyc, e.g. most ways of using latest master / installing from git.

JukkaL pushed a commit that referenced this issue Jan 8, 2021
Fixes #9888.

I applied the following patch to typeshed and ran self check:
```
+@overload
+def getattr(__o: Any, name: str, __default: None) -> Optional[Any]: ...
+@overload
 def getattr(__o: Any, name: str, __default: Any = ...) -> Any: ...
 ```

Co-authored-by: hauntsaninja <>
@Arpafaucon
Copy link
Author

Thanks for the fix 👍 and for the explanation, I did not know mypy had its own compiler, that's impressive.

I'll wait for this to land in the next release, and use a non-compiled version in the meantime

ilevkivskyi pushed a commit that referenced this issue Jan 19, 2021
Fixes #9888.

I applied the following patch to typeshed and ran self check:
```
+@overload
+def getattr(__o: Any, name: str, __default: None) -> Optional[Any]: ...
+@overload
 def getattr(__o: Any, name: str, __default: Any = ...) -> Any: ...
 ```

Co-authored-by: hauntsaninja <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants