stubdoc: Fix crash on non-str docstring#15623
Merged
hauntsaninja merged 2 commits intopython:masterfrom Jul 8, 2023
Merged
Conversation
Encourted this while testing stubgen on pandas:
```console
$ stubgen -p pandas
Traceback (most recent call last):
File "/tmp/.venv/bin/stubgen", line 8, in <module>
sys.exit(main())
File "mypy/stubgen.py", line 1945, in main
File "mypy/stubgen.py", line 1799, in generate_stubs
File "/tmp/.venv/lib/python3.10/site-packages/mypy/stubgenc.py", line 212, in generate_stub_for_c_module
generate_c_type_stub(
File "/tmp/.venv/lib/python3.10/site-packages/mypy/stubgenc.py", line 528, in generate_c_type_stub
generate_c_function_stub(
File "/tmp/.venv/lib/python3.10/site-packages/mypy/stubgenc.py", line 337, in generate_c_function_stub
inferred = sig_gen.get_method_sig(
File "/tmp/.venv/lib/python3.10/site-packages/mypy/stubgenc.py", line 140, in get_method_sig
inferred = self.get_function_sig(cls, module_name, class_name)
File "/tmp/.venv/lib/python3.10/site-packages/mypy/stubgenc.py", line 120, in get_function_sig
inferred = infer_sig_from_docstring(docstr, name)
File "/tmp/.venv/lib/python3.10/site-packages/mypy/stubdoc.py", line 264, in infer_sig_from_docstring
tokens = tokenize.tokenize(io.BytesIO(docstr.encode("utf-8")).readline)
AttributeError: 'getset_descriptor' object has no attribute 'encode'
```
This is because of the definition of docstring as a descriptor here
https://github.com/pandas-dev/pandas/blob/main/pandas/_libs/properties.pyx
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Encourted this while testing stubgen on pandas:
This is because of the definition of docstring as a descriptor here https://github.com/pandas-dev/pandas/blob/main/pandas/_libs/properties.pyx
(Explain how this PR changes mypy.)