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

Fix using report() with a Module visitor #368

Merged

Conversation

duzumaki
Copy link
Contributor

@duzumaki duzumaki commented Jul 28, 2023

Currently in fixit v2.0.0.post1

calling self.report() in a Module node visitor like so:

    def visit_Module(self, node: cst.Module) -> None:
        self.report(node)

resulted in a libcst error where the module node was passed into
self.get_metadata:

self.get_metadata(ParentNodeProvider, node)

I am assuing this fails intentionally in libcst because what is the parent of a module?
Nothing.

It results in this error:

python3.10/site-packages/fixit/rule.py:151: in node_comments
    parent = self.get_metadata(ParentNodeProvider, node)
python3.10/site-packages/libcst/_metadata_dependent.py:136: in get_metadata
    value = self.metadata[key][node]
E   KeyError: Module(
E       body=[
E           SimpleStatem
-the rest of the error is just the rest of the module tree-

This PR aims to fix that by yielding any comments that exist in
a module's header(which is the intention of the node_comments function for header comments)

and if the current visitor is not a module node
it will check its parent with the ParentNodeProvider like it already does.

fixes: #367

@facebook-github-bot
Copy link

Hi @duzumaki!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@duzumaki duzumaki force-pushed the fix_mode_comment_yielding_in_report branch 2 times, most recently from e548a07 to 7b2f33e Compare July 28, 2023 22:22
Currently in fixit v2.0.0.post1

calling self.report() in a Module node visitor like so:
```
    def visit_Module(self, node: cst.Module) -> None:
        self.report(node)
```

resulted in a libcst error where the module node was passed into
self.get_metadata like so:

```
self.get_metadata(ParentNodeProvider, node)
```

I am assuing this fails intentionally in libcst because what is the parent of a module?
Nothing.

It results in this error:

```
python3.10/site-packages/fixit/rule.py:151: in node_comments
    parent = self.get_metadata(ParentNodeProvider, node)
python3.10/site-packages/libcst/_metadata_dependent.py:136: in get_metadata
    value = self.metadata[key][node]
E   KeyError: Module(
E       body=[
E           SimpleStatem
-the rest of the error is just the rest of the module tree-
```

This PR aims to fix that by yielding any comments that exist in
a module's header(which is the current intention of fixit)

and if the current visitor is not a module node
it will check its parent with the ParentNodeProvider like it already does.
@duzumaki duzumaki force-pushed the fix_mode_comment_yielding_in_report branch from 7b2f33e to 7fe4bb3 Compare July 28, 2023 22:24
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 29, 2023
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@amyreese amyreese merged commit 7e9c8d1 into Instagram:main Aug 9, 2023
12 checks passed
@amyreese
Copy link
Member

amyreese commented Aug 9, 2023

Thank you for spotting and fixing this! 🥂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: using leave/visit_Module with report() results in libcst metadata key error
4 participants