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

convert_type_comments now preserves comments following type comments #702

Merged
merged 1 commit into from
Jun 20, 2022

Conversation

superbobry
Copy link
Contributor

Summary

Prior to this PR convert_type_comments codemod stripped any comments following a type comment. So, for example,

y = 5  # type: int  # foo

was converted to

y: int = 5

instead of

y: int = 5  # foo

The PR changes the codemod to preserve any such comments.

Test Plan

Added a new test case.

@facebook-github-bot
Copy link

Hi @superbobry!

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!

@superbobry superbobry force-pushed the comment-after-type-comment branch from 72e4550 to 48f6398 Compare June 15, 2022 22:02
@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 Jun 16, 2022
@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!

@zsol zsol requested a review from stroxler June 16, 2022 08:43
@zsol
Copy link
Member

zsol commented Jun 16, 2022

I'll let @stroxler chime in, but let me ask: what happens for y = 5 # foo # type: int?

@codecov-commenter
Copy link

Codecov Report

Merging #702 (48f6398) into main (ff5fcf8) will decrease coverage by 0.00%.
The diff coverage is 92.85%.

@@            Coverage Diff             @@
##             main     #702      +/-   ##
==========================================
- Coverage   94.79%   94.79%   -0.01%     
==========================================
  Files         246      246              
  Lines       25689    25703      +14     
==========================================
+ Hits        24353    24366      +13     
- Misses       1336     1337       +1     
Impacted Files Coverage Δ
libcst/codemod/commands/convert_type_comments.py 94.96% <90.00%> (-0.21%) ⬇️
...demod/commands/tests/test_convert_type_comments.py 97.43% <100.00%> (+0.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff5fcf8...48f6398. Read the comment docs.

@superbobry
Copy link
Contributor Author

Thanks @zsol! y = 5 # foo # type: int is not a valid type comment according to PEP-484:

In some cases, linting tools or other comments may be needed on the same line as a type comment. In these cases, the type comment should be before other comments and linting markers:

# type: ignore # <comment or other marker>

For example,

    y = 5  # type: int  # foo

is converted to

    y: int = 5  # foo
@superbobry superbobry force-pushed the comment-after-type-comment branch from 48f6398 to 91a917d Compare June 16, 2022 09:08
@zsol zsol merged commit 306a5f8 into Instagram:main Jun 20, 2022
@zsol
Copy link
Member

zsol commented Jun 20, 2022

Thanks for the contribution :)

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Sep 16, 2022
0.4.7 - 2022-07-12

Fixed
* Fix get_qualified_names_for matching on prefixes of the given name by @lpetre in Instagram/LibCST#719

Added
* Implement lazy loading mechanism for expensive metadata providers by @Chenguang-Zhu in Instagram/LibCST#720


0.4.6 - 2022-07-04

New Contributors
- @superbobry made their first contribution in Instagram/LibCST#702

Fixed
- convert_type_comments now preserves comments following type comments by @superbobry in Instagram/LibCST#702
- QualifiedNameProvider optimizations
  - Cache the scope name prefix to prevent scope traversal in a tight loop by @lpetre in Instagram/LibCST#708
  - Faster qualified name formatting by @lpetre in Instagram/LibCST#710
  - Prevent unnecessary work in Scope.get_qualified_names_for_ by @lpetre in Instagram/LibCST#709
- Fix parsing of parenthesized empty tuples by @zsol in Instagram/LibCST#712
- Support whitespace after ParamSlash by @zsol in Instagram/LibCST#713
- [parser] bail on deeply nested expressions by @zsol in Instagram/LibCST#718


0.4.5 - 2022-06-17

New Contributors

-   @zzl0 made their first contribution in Instagram/LibCST#704

Fixed

-   Only skip supported escaped characters in f-strings by @zsol in Instagram/LibCST#700
-   Escaping quote characters in raw string literals causes a tokenizer error by @zsol in Instagram/LibCST#668
-   Corrected a code example in the documentation by @zzl0 in Instagram/LibCST#703
-   Handle multiline strings that start with quotes by @zzl0 in Instagram/LibCST#704
-   Fixed a performance regression in libcst.metadata.ScopeProvider by @lpetre in Instagram/LibCST#698


0.4.4 - 2022-06-13

New Contributors

-   @adamchainz made their first contribution in Instagram/LibCST#688

Added

-   Add package links to PyPI by @adamchainz in Instagram/LibCST#688
-   native: add overall benchmark by @zsol in Instagram/LibCST#692
-   Add support for PEP-646 by @zsol in Instagram/LibCST#696

Updated

-   parser: use references instead of smart pointers for Tokens by @zsol in Instagram/LibCST#691
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.

4 participants