asottile / pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Formatting bug? Triple-quote changed to 2x triple-quote

mpasternak opened this issue · comments

Hi there,

either a bug in my code/comments or a bug in pyupgrade.

Please download the file:
https://github.com/iplweb/bpp/blob/e7f0c818b43a47f1926b72a42f9d2ac3ad981460/src/bpp/models/jednostka.py#L233

Then format it using pyugprade 3.15.0 and then check the comment near line 234. It will change to:

def pracownicy(self):
        """Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli
        aktualni pracownicy, obecni pracownicy"""y"""
        return Autor.objects.filter(pk__in=self.aktualni_autorzy(), pokazuj=True)

Is this a known bug? Is there something wrong with my code?

can't reproduce -- must be some other tool that you're confusing for pyupgrade

I am able to reproduce it on a clean virtualenvironment with this versions:

[d] pip list                                                       15:39:11
Package     Version
----------- -------
pip         23.3.1
pyupgrade   3.15.0
tokenize-rt 5.2.0

[d] python --version                                               15:39:12
Python 3.12.0

[d] curl "https://raw.githubusercontent.com/iplweb/bpp/e7f0c818b43a47f1926b72a42f9d2ac3ad981460/src/bpp/models/jednostka.py" > jednostka.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16044  100 16044    0     0  65410      0 --:--:--


[d] grep y\" jednostka.py                                          15:41:13
        aktualni pracownicy, obecni pracownicy"""


[d] pyupgrade jednostka.py                                         15:41:15
Rewriting jednostka.py

[d] grep y\" jednostka.py                                          15:41:19
        aktualni pracownicy, obecni pracownicy"""y"""

... and I have exactly the same behavior with version installed from git.

Which version of pyupgrade were you using that you're unable to reproduce it?

I can reproduce, running pyupgrade 3.15.0 on Python 3.12.1 with no options on:

def thing():
    """Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli
    aktualni pracownicy, obecni pracownicy"""
    ...

Gives:

def thing():
    """Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli
    aktualni pracownicy, obecni pracownicy"""y"""
    ...
 def thing():
     """Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli
-    aktualni pracownicy, obecni pracownicy"""
+    aktualni pracownicy, obecni pracownicy"""y"""
     ...

alright I can with 3.12 now. I had only tried 3.8 and 3.10 and the versions you claimed

next time include your actual information in your report

this is a bug in cpython -- please report there. here's a little testcase you can take too:

import io
import tokenize

src = '''\
def thing():
    """Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli
    aktualni pracownicy, obecni pracownicy"""
    ...
'''
tokens = list(tokenize.generate_tokens(io.StringIO(src).readline))
assert tokens[7].end == (3, 45), tokens[7].end

Will do, thanks for taking time to analyze this @asottile & @hugovk

you can work around this by ensuring your docstrings are ascii-only

Reported to CPython at python/cpython#112943.

@hugovk thanks, I planned to report it some time later, but the way you did it is obviously much more professional than I could ever come up with.

I'm just a small developer doing my own thing, I did not expect that such a small minor bug would reach cpython repo. Thank you!