andrews4s / unpyc37

Decompiler for Python 3.7 (forked from https://github.com/figment/unpyc3)
GNU General Public License v3.0
57 stars 19 forks source link

3.6+ format string { should get escaped to {{ #1

Closed rocky closed 5 years ago

rocky commented 5 years ago

This code from 3.7 dataclasses.py is an example of where {{ gets turned into {

def _repr_fn(fields):
    return _create_fn('__repr__',
                      ('self',),
                      ['return self.__class__.__qualname__ + f"(' +
                       ', '.join([f"{f.name}={{self.{f.name}!r}}"
                                  for f in fields]) +
                       ')"'])

Inside the bytecode, in the corresponding LOAD_CONST's only { or } appear. They therefore need to be doubled in decomplation.

unpyc37 run on the 3.7 bytecode for the above gives:

def _repr_fn(fields):
    return _create_fn('__repr__', ('self',), ['return self.__class__.__qualname__ + f"(' + ', '.join([f'{f.name}={self.{f.name}!r}' for f in fields]) + ')"'])
andrews4s commented 5 years ago

This should be fixed in bd0e1bcb8f73d91775f928ecbff5ceb411ba7068.

rocky commented 5 years ago

It is - thanks.