Skip to content

Fix type expected by stubgenc #8888

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 1 commit into from
Jul 31, 2020
Merged

Fix type expected by stubgenc #8888

merged 1 commit into from
Jul 31, 2020

Conversation

henryiii
Copy link
Contributor

In investigating a crash when running on a PyBind11 module, I noticed a mismatch in the types; infer_prop_type_from_docstring can clearly get None, but it has a type of plain str. Fix the annotation to match the expectation. Now, when rebuilding Mypy, the error goes away and this now works without crashing, and can completely generate stubs.

Here's one of the uses where None is obviously possible:

mypy/mypy/stubgenc.py

Lines 220 to 221 in d104886

docstr = getattr(obj, '__doc__', None)
inferred = infer_prop_type_from_docstring(docstr)

Fixes #7692.

Example printout when this error is seen:

    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 51, in generate_stub_for_c_module
  File "mypy/stubgenc.py", line 273, in generate_c_type_stub
  File "mypy/stubgenc.py", line 221, in generate_c_property_stub
TypeError: str object expected; got None

@JelleZijlstra
Copy link
Member

Looks good. I wonder why mypy itself didn't catch that—are we running with strict-optional off perhaps?

@t-fi
Copy link

t-fi commented Jul 28, 2020

Hi, will this PR be merged? It looks quite simple and finished, or is there some work to be done still? I am interested since I have this issue when running stubgen on several different modules.

For anyone interested, you can install the fixed version via:
python3 -m pip install -U git+git://github.com/henryiii/mypy.git@7f4dc937d338875104b0cd2f19d8f06d24713e55

I would not recommend installing some strangers repo on any machine. You can install that version once, generate stubs, and then remove it again :)

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the PR!

@JukkaL JukkaL merged commit ea9291d into python:master Jul 31, 2020
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.

stubgen and C Extensions (pyd)
4 participants