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

Cannot create stubs for safe-ds #80

Closed
lars-reimann opened this issue Mar 29, 2024 · 1 comment · Fixed by #108
Closed

Cannot create stubs for safe-ds #80

lars-reimann opened this issue Mar 29, 2024 · 1 comment · Fixed by #108
Assignees
Labels
bug 🪲 Something isn't working released Included in a release

Comments

@lars-reimann
Copy link
Member

lars-reimann commented Mar 29, 2024

Describe the bug

Generating stubs for the safe-ds library leads to a various errors:

1. Error

Traceback (most recent call last):
  File "C:\Users\Lars\AppData\Local\pypoetry\Cache\virtualenvs\safe-ds-stubgen-VELKLkPa-py3.12\Scripts\\safe-ds-stubgen", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\main.py", line 14, in main
    cli()
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 20, in cli
    _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.naming_convert)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 99, in _run_api_command
    api = get_api(package, src_dir_path, docstring_style, is_test_run)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_get_api.py", line 75, in get_api
    walker.walk(tree)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 30, in walk
    self.__walk(tree, set())
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 42, in __walk
    self.__enter(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 83, in __enter
    method(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 260, in enter_funcdef
    results = self._parse_results(node, function_id)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 430, in _parse_results
    ret_type = self._infer_type_from_return_stmts(node)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 476, in _infer_type_from_return_stmts
    type_ = mypy_expression_to_sds_type(return_stmt.expr)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_mypy_helpers.py", line 105, in mypy_expression_to_sds_type
    raise TypeError("Unexpected expression type.")  # pragma: no cover
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Unexpected expression type.

2. Error (after no longer raising a type error there)

Traceback (most recent call last):
  File "C:\Users\Lars\AppData\Local\pypoetry\Cache\virtualenvs\safe-ds-stubgen-VELKLkPa-py3.12\Scripts\\safe-ds-stubgen", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\main.py", line 14, in main
    cli()
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 20, in cli
    _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.naming_convert)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 99, in _run_api_command
    api = get_api(package, src_dir_path, docstring_style, is_test_run)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_get_api.py", line 75, in get_api
    walker.walk(tree)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 30, in walk
    self.__walk(tree, set())
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 42, in __walk
    self.__enter(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 83, in __enter
    method(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 215, in enter_classdef
    is_public=self._is_public(node.name, name),
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 1008, in _is_public
    raise TypeError(
TypeError: Expected parent for Writer in module gyp.common to be a class or a module.

3. Error (after disabling the 2. one)

Traceback (most recent call last):
  File "C:\Users\Lars\AppData\Local\pypoetry\Cache\virtualenvs\safe-ds-stubgen-VELKLkPa-py3.12\Scripts\\safe-ds-stubgen", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\main.py", line 14, in main
    cli()
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 20, in cli
    _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.naming_convert)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 99, in _run_api_command
    api = get_api(package, src_dir_path, docstring_style, is_test_run)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_get_api.py", line 75, in get_api
    walker.walk(tree)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 30, in walk
    self.__walk(tree, set())
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 42, in __walk
    self.__enter(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 83, in __enter
    method(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 342, in enter_assignmentstmt
    for assignment in self._parse_attributes(lvalue, node.unanalyzed_type, is_static=False):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 563, in _parse_attributes
    assert isinstance(lvalue, mp_nodes.NameExpr | mp_nodes.MemberExpr | mp_nodes.TupleExpr)
AssertionError

4. Error (after disabling assertion)

Traceback (most recent call last):
  File "C:\Users\Lars\AppData\Local\pypoetry\Cache\virtualenvs\safe-ds-stubgen-VELKLkPa-py3.12\Scripts\\safe-ds-stubgen", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\main.py", line 14, in main
    cli()
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 20, in cli
    _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.naming_convert)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 99, in _run_api_command
    api = get_api(package, src_dir_path, docstring_style, is_test_run)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_get_api.py", line 75, in get_api
    walker.walk(tree)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 30, in walk
    self.__walk(tree, set())
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 42, in __walk
    self.__enter(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 83, in __enter
    method(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 260, in enter_funcdef
    results = self._parse_results(node, function_id)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 427, in _parse_results
    ret_type = self.mypy_type_to_abstract_type(node_ret_type, unanalyzed_ret_type)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 938, in mypy_type_to_abstract_type
    raise ValueError("Unexpected type.")  # pragma: no cover
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Unexpected type.

5. Error (after disabling error 4)

Traceback (most recent call last):
  File "C:\Users\Lars\AppData\Local\pypoetry\Cache\virtualenvs\safe-ds-stubgen-VELKLkPa-py3.12\Scripts\\safe-ds-stubgen", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\main.py", line 14, in main
    cli()
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 20, in cli
    _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.naming_convert)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\cli\_cli.py", line 99, in _run_api_command
    api = get_api(package, src_dir_path, docstring_style, is_test_run)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_get_api.py", line 75, in get_api
    walker.walk(tree)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 30, in walk
    self.__walk(tree, set())
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 77, in __walk
    self.__walk(child_node, visited_nodes)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 42, in __walk
    self.__enter(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_walker.py", line 83, in __enter
    method(node)
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 252, in enter_funcdef
    arguments = self._parse_parameter_data(node, function_id)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 715, in _parse_parameter_data
    arg_type = self.mypy_type_to_abstract_type(mypy_type)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 907, in mypy_type_to_abstract_type
    name, qname = self._find_alias(mypy_type.name)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Repositories\safe-ds\Stub-Generator\src\safeds_stubgen\api_analyzer\_ast_visitor.py", line 985, in _find_alias
    raise ValueError(f"It was not possible to find out where the alias {type_name} was defined.")
ValueError: It was not possible to find out where the alias np.array was defined.

...

To Reproduce

Used command:

C:\Users\Lars\AppData\Local\pypoetry\Cache\virtualenvs\safe-ds-stubgen-VELKLkPa-py3.12\Scripts\safe-ds-stubgen -p safeds --docstyle NUMPYDOC -o C:\out -nc -v -s E:\Repositories\safe-ds\Library\

Versions:

  • Python: 3.12.2
  • safe-ds: Latest main
  • safe-ds-stubgen: Latest main

Expected behavior

Stubs should be created.

Screenshots (optional)

No response

Additional Context (optional)

No response

@lars-reimann lars-reimann added the bug 🪲 Something isn't working label Mar 29, 2024
@Masara Masara moved this from Backlog to In Progress in Library Analysis Apr 11, 2024
@Masara Masara linked a pull request Apr 11, 2024 that will close this issue
@Masara Masara moved this from In Progress to Ready for Review in Library Analysis Apr 11, 2024
lars-reimann pushed a commit that referenced this issue Apr 25, 2024
Closes #80 

### Summary of Changes
Fixed the stub generator, it should now run with the Library project.

To run the script, use the following command:
`safe-ds-stubgen -p "Library" -o "path/to/out" -nc -s
"path/to/Library/src" --docstyle NUMPYDOC`

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
@github-project-automation github-project-automation bot moved this from Ready for Review to ✔️ Done in Library Analysis Apr 25, 2024
lars-reimann pushed a commit that referenced this issue May 4, 2024
## [0.3.0](v0.2.0...v0.3.0) (2024-05-04)

### Features

* Added handling for sequence classes ([#127](#127)) ([cb061ab](cb061ab)), closes [#126](#126)
* DocString result names for Safe-DS stub results ([#101](#101)) ([fe163e3](fe163e3)), closes [#100](#100)
* Examples from docstrings are also taken over to stub docstrings ([#116](#116)) ([6665186](6665186)), closes [#115](#115)
* Replace the docstring_parser library with Griffe ([#79](#79)) ([9b2f802](9b2f802))

### Bug Fixes

* `Self` types as results are translated to class names  ([#110](#110)) ([4554a56](4554a56)), closes [#86](#86)
* Creating stubs with relative paths for source and output directories ([#128](#128)) ([b4493c9](b4493c9)), closes [#125](#125)
* Docstrings have the correct indentation for nested classes (stubs) ([#114](#114)) ([c7b8550](c7b8550)), closes [#113](#113)
* Fixed a bug where double ? would be generated for stubs ([#103](#103)) ([c35c6ac](c35c6ac)), closes [#87](#87) [#87](#87)
* Fixed a bug where imports would not check reexports for shortest path ([#112](#112)) ([48c5367](48c5367)), closes [#82](#82)
* Fixed a bug where results in stubs would not be named ([#131](#131)) ([4408c84](4408c84)), closes [#100](#100)
* Fixed a bug which prevented mypy version update ([#107](#107)) ([501d2cd](501d2cd))
* Fixed the stubs generator ([#108](#108)) ([9ad6df6](9ad6df6)), closes [#80](#80)
* Generated names of callback results start with result, not with param ([#104](#104)) ([6e696e9](6e696e9)), closes [#85](#85)
* Include lines of examples that start with `...` ([#130](#130)) ([3477b4a](3477b4a)), closes [#129](#129)
* No "// TODO ..." if return type is explicitly `None` ([#111](#111)) ([08e345f](08e345f)), closes [#83](#83)
* Removed the Epydoc parser ([#89](#89)) ([684a101](684a101))
* Replaced tabs with 4 spaces ([#105](#105)) ([8e7aa5d](8e7aa5d)), closes [#84](#84)
* The file structure of stubs resembles the "package" path. ([#106](#106)) ([ff1800e](ff1800e)), closes [#81](#81)
* Translation of callable ([#102](#102)) ([c581e6a](c581e6a)), closes [#88](#88) [#88](#88)
@lars-reimann
Copy link
Member Author

🎉 This issue has been resolved in version 0.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lars-reimann lars-reimann added the released Included in a release label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working released Included in a release
Projects
Status: ✔️ Done
Development

Successfully merging a pull request may close this issue.

2 participants