Skip to content

Fix unintentionally overwritten method_list #7

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 2 commits into from
Oct 11, 2023

Conversation

nhtlongcs
Copy link
Contributor

@nhtlongcs nhtlongcs commented Oct 7, 2023

I would like to thank the authors of this repository for their work on this project, which has been invaluable for AI4code projects. However, I found a bug in the code that should not be present.

The error is that the method_list variable is overwritten on line 56. This means that the method_list variable will only contain the methods of the last extend time.

method_list = []
cls_metadata = []
for _cls in cls_list:
cls_info = parser.get_class_metadata(_cls)
cls_info["code"] = get_node_text(_cls)
cls_method = []
method_list = parser.get_function_list(_cls)
for method in method_list:
method_info = parser.get_function_metadata(method)
method_info['code'] = get_node_text(method)
cls_method.append(method_info)
cls_info["method"] = cls_method
cls_metadata.append(cls_info)
method_list.extend(method_list)

To fix this error, instead of overwriting the method_list variable, I created a new variable, current_class_methods, to store the methods of the current class (check out my PR). Then, I extend the current_class_methods variable to the method_list list safely (line 64). This ensures that the method_list list contains all of the methods for all of the classes in the method_list list.

Here is the corrected code,

  cls_list = parser.get_class_list(root_node)
  method_list = []
  cls_metadata = []
  for _cls in cls_list:
      cls_info = parser.get_class_metadata(_cls)
      cls_info["code"] = get_node_text(_cls)

      cls_method = []
      current_class_methods = parser.get_function_list(_cls)
      for method in current_class_methods:
          method_info = parser.get_function_metadata(method)
          method_info['code'] = get_node_text(method)
          cls_method.append(method_info)

      cls_info["method"] = cls_method
      cls_metadata.append(cls_info)
      method_list.extend(current_class_methods)

@nhtlongcs
Copy link
Contributor Author

Hi @nmd2k,

Could you please review my PR for a bug that could affect the dependent project? I'd really appreciate it.

@nmd2k nmd2k self-requested a review October 11, 2023 04:17
@nmd2k nmd2k self-assigned this Oct 11, 2023
@nmd2k nmd2k added the bug Something isn't working label Oct 11, 2023
@nmd2k
Copy link
Collaborator

nmd2k commented Oct 11, 2023

Thank you, my silly mistake there. I will try to check other language and release a new version of this.
Thank you.

@nmd2k nmd2k merged commit 49dae61 into FSoft-AI4Code:main Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants