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

Internal error when docstring end follows double quote #1452

Closed
hugovk opened this issue May 22, 2020 · 2 comments
Closed

Internal error when docstring end follows double quote #1452

hugovk opened this issue May 22, 2020 · 2 comments
Labels
C: invalid code Black destroyed a valid Python file T: bug Something isn't working

Comments

@hugovk
Copy link
Contributor

hugovk commented May 22, 2020

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Take this file:
def thing():
    """Controls vertical alignment of fields
    Arguments:

    valign - vertical alignment, one of "t", "m", or "b" """
    return

(Simplified from https://github.com/jazzband/prettytable/blob/master/prettytable.py)

  1. Run Black on it with these arguments: black 1.py
  2. See error:
$ black 1.py
error: cannot format 1.py: INTERNAL ERROR: Black produced invalid code: EOL while scanning string literal (<unknown>, line 5). Please report a bug on https://github.com/psf/black/issues.  This invalid output might be helpful: /var/folders/kt/j77sf4_n6fnbx6pg199rbx700000gn/T/blk_vs1w_3yc.log
Oh no! 💥 💔 💥
1 file failed to reformat.
$ cat /var/folders/kt/j77sf4_n6fnbx6pg199rbx700000gn/T/blk_vs1w_3yc.log
  File "/Users/hugo/github/black/src/black/__init__.py", line 6037, in assert_equivalent
    dst_ast = parse_ast(dst)
  File "/Users/hugo/github/black/src/black/__init__.py", line 5948, in parse_ast
    return ast27.parse(src)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/typed_ast/ast27.py", line 50, in parse
    return _ast27.parse(source, filename, mode)
def thing():
    """Controls vertical alignment of fields
    Arguments:

    valign - vertical alignment, one of "t", "m", or "b""""
    return

Expected behavior A clear and concise description of what you expected to happen.

File was formatted.

Environment (please complete the following information):

  • Version: master
  • OS and Python version: macOS/Python 3.8.3.

Does this bug also happen on master? To answer this, you have two options:

Yes with master. No with latest 19.10b0 release, which does not change the file.

Additional context Add any other context about the problem here.

It's fine with single quotes instead in "t", "m", or "b", or with a newline after "b".

@hugovk hugovk added the T: bug Something isn't working label May 22, 2020
@hugovk
Copy link
Contributor Author

hugovk commented May 22, 2020

Git bisect points to a4c11a7 as the first bad commit, from PR #1053, "Re-indent the contents of docstrings".

PR #1417 fixed some other docstring things (#1415) but not this case.

Here's a smaller failing case:

def containing_quotes():
    """No quotes here

    "quotes here" """
    pass

Or:

def containing_quotes():
    """No quotes here

    quote here" """
    pass

alexmv added a commit to alexmv/black that referenced this issue May 22, 2020
0;95;0c
The PEP 257 algorithm used in psf#1053 results in trimming trailing
whitespace in docstrings -- see psf#1415 and fixes in psf#1417.  Removing
trailing whitespace may result in four quotes in a row:

    def foo():
        """"Some content
        and more "here" """
        pass

When closing the docstring, escape any trailing quote characters that
it matches, if they are not already escaped.

Fixes psf#1452.
alexmv added a commit to alexmv/black that referenced this issue May 22, 2020
The PEP 257 algorithm used in psf#1053 results in trimming trailing
whitespace in docstrings -- see psf#1415 and fixes in psf#1417.  Removing
trailing whitespace may result in four quotes in a row:

    def foo():
        """"Some content
        and more "here" """
        pass

When closing the docstring, escape any trailing quote characters that
it matches, if they are not already escaped.

Fixes psf#1452.
alexmv added a commit to alexmv/black that referenced this issue Jul 31, 2020
The PEP 257 algorithm used in psf#1053 results in trimming trailing
whitespace in docstrings -- see psf#1415.

Adjust the algorithm to preserve leading and trailing whitespace; this
reverts the changes in psf#1417.  This diverges from PEP 257, but better
retains the contents of the docstring.

Fixes psf#1452 because we no longer can end up with four trailing quotes.
@ichard26 ichard26 added the C: invalid code Black destroyed a valid Python file label Aug 4, 2020
@ambv
Copy link
Collaborator

ambv commented Aug 25, 2020

Fixed by #1623.

@ambv ambv closed this as completed Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: invalid code Black destroyed a valid Python file T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants