dflook / python-minifier

Transform Python source code into its most compact representation
MIT License
560 stars 41 forks source link

Broken string in 2.10.0 #107

Closed richardthegit closed 6 hours ago

richardthegit commented 7 hours ago

There seems to be a issue introduced in 2.10.0 - the following code is broken after minify (no minify options specified on command line):

class RichText:
    BOLD = '\033[1m'
    END = '\033[0m'

    def p(self, msg, style = END, bold = False):
        print(f'{self.BOLD if bold else ""}{style}{msg}{self.END}', flush = True)

The last line is minified to:

def p(A,msg,style=END,bold=False):print(f"{A.BOLD if bold else""}{style}{msg}{A.END}",flush=True)

Note that the string contains nested double quotes. This doesn't happen when I minify on python-minifier.com, which is 2.9.0.

Many thanks for this awesome tool - any ideas on how to work-around this appreciated! 🫡

richardthegit commented 7 hours ago

Well, an obvious work-around is to replace that blank string with a variable! 🤦‍♂️

dflook commented 7 hours ago

Hello @richardthegit, nested quotes in f-strings are valid syntax in Python 3.12. python-minifer targets the running version of python. Is this broken in some other way I can't see?

I assume you installed python-minifier using a 3.12 interpreter. If you need the output to work on say, Python 3.11, you'll need to run python-minifier using the 3.11 interpreter.

richardthegit commented 6 hours ago

Ahh - thanks for the quick reply @dflook - that's exactly what I was doing (compiling on 3.12, running on 3.11). I had no idea nested quotes were okay now! My bad.

Sorry to have troubled you, and thanks again for pyminify. 😁

richardthegit commented 6 hours ago

Closed.