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

expression: fix SimpleString's quote method #704

Merged
merged 2 commits into from
Jun 17, 2022
Merged

Conversation

zzl0
Copy link
Contributor

@zzl0 zzl0 commented Jun 17, 2022

Summary

Fix #636

>>> from libcst import *
>>> m = parse_module('''""""foo"""''')
>>> m.body[0].body[0].value.raw_value
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\zsolz\projects\libcst\libcst\_nodes\expression.py", line 682, in raw_value
    quote_len = len(self.quote)
  File "C:\Users\zsolz\projects\libcst\libcst\_nodes\expression.py", line 666, in quote
    raise Exception("Invalid string {self.value}")
Exception: Invalid string {self.value}

Test Plan

  1. Unit test
  2. Manual test
>>> from libcst import *
>>> m = parse_module('''""""foo"""''')
>>> m.body[0].body[0].value.raw_value
'"foo'

@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 17, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2022

Codecov Report

Merging #704 (26442dc) into main (6f28c79) will increase coverage by 0.00%.
The diff coverage is 90.90%.

@@           Coverage Diff           @@
##             main     #704   +/-   ##
=======================================
  Coverage   94.79%   94.80%           
=======================================
  Files         246      247    +1     
  Lines       25692    25701    +9     
=======================================
+ Hits        24356    24365    +9     
  Misses       1336     1336           
Impacted Files Coverage Δ
libcst/_nodes/expression.py 96.66% <50.00%> (ø)
libcst/_nodes/tests/test_simple_string.py 100.00% <100.00%> (ø)

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 6f28c79...26442dc. Read the comment docs.

Copy link
Member

@zsol zsol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! Let's add that license header before merging

libcst/_nodes/tests/test_simple_string.py Show resolved Hide resolved
@lpetre lpetre merged commit 7ca1bd1 into Instagram:main Jun 17, 2022
@zzl0
Copy link
Contributor Author

zzl0 commented Jun 17, 2022

Thanks @zsol, @lpetre for reviewing the code.

I noticed that we have code like below (link). Just curious why does it need type hint? since quote = "" is more succinct, and both human and machine can easily infer its type is a string.

quote: str = ""

@bgw
Copy link
Contributor

bgw commented Jun 20, 2022

Just curious why does it need type hint?

You're probably right, there's probably no reason for it to be there.

@zzl0
Copy link
Contributor Author

zzl0 commented Jun 20, 2022

@bgw thanks for your reply. Yeah, I also think there's probably no reason for it to be there:

  1. It can hurt readability (I have seen some code like below).
        a_long_name_name: AVeryLongLongLongLongLongClassName = 
            AVeryLongLongLongLongLongClassName(param1, param2, ...)
  1. Statically-typed languages (Rust, C++, Java etc) recommends using type inference for this simple initialization case to improve DevX by reducing the ceremony.

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.

SimpleString.raw_value cannot handle """"foo"""
6 participants