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

Commits on Jul 8, 2023

  1. stubdoc: Fix crash on non-str docstring

    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
    hamdanal committed Jul 8, 2023
    Configuration menu
    Copy the full SHA
    bd09d51 View commit details
    Browse the repository at this point in the history
  2. Self check

    hamdanal committed Jul 8, 2023
    Configuration menu
    Copy the full SHA
    f6c74a5 View commit details
    Browse the repository at this point in the history