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

stubdoc: Fix crash on non-str docstring #15623

Merged
merged 2 commits into from
Jul 8, 2023

Conversation

hamdanal
Copy link
Collaborator

@hamdanal hamdanal commented Jul 8, 2023

Encourted this while testing stubgen on pandas:

$ 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

(Explain how this PR changes mypy.)

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
@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2023

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thank you!

@hauntsaninja hauntsaninja merged commit ebfea94 into python:master Jul 8, 2023
@hamdanal hamdanal deleted the stubdoc-docstr branch July 9, 2023 06:43
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