Skip to content

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

Closed

Description

@mpasternak

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?

Activity

  1. asottile commented on Dec 9, 2023

    @asottile
    Owner

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

  2. mpasternak commented on Dec 9, 2023

    @mpasternak
    Author

    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"""
    
  3. mpasternak commented on Dec 9, 2023

    @mpasternak
    Author

    ... 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?

  4. hugovk commented on Dec 9, 2023

    @hugovk
    Contributor

    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"""
         ...
  5. asottile commented on Dec 9, 2023

    @asottile
    Owner

    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

  6. asottile commented on Dec 9, 2023

    @asottile
    Owner

    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
  7. mpasternak commented on Dec 9, 2023

    @mpasternak
    Author

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

  8. asottile commented on Dec 9, 2023

    @asottile
    Owner

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

  9. hugovk commented on Dec 10, 2023

    @hugovk
    Contributor

    Reported to CPython at python/cpython#112943.

  10. mpasternak commented on Dec 10, 2023

    @mpasternak
    Author

    @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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions