Duroktar / Wolf

Wolf is a VsCode extension that enables live inspection of Python code in the editor.
Other
128 stars 7 forks source link

wolf runs into error with emojis #53

Closed Almenon closed 3 years ago

Almenon commented 3 years ago

Python code:

print("🍆") #?

Expected result: Code runs successfully Actual result:

UnicodeEncodeError: 'charmap'
codec can 't encode character '\
U0001f346 ' in position 0: character maps to <undefined

In arepl I avoid this problem by specifying utf8:

        else if (process.platform == "win32") {
            // needed for windows for encoding to match what it would be in terminal
            // https://docs.python.org/3/library/sys.html#sys.stdin
            options.env.PYTHONIOENCODING = "utf8"
        }

And in arepl backend I also specify the encoding. I'm not sure if I need to do it twice 🤔

    # arepl should treat stdout as tty device
    # windows uses utf8 as encoding for tty device
    # so we need to manually specify it in that case
    # https://docs.python.org/3/library/sys.html#sys.stdout
    if sys.platform == "win32":
        encoding = "utf8"
    # arepl is ran via node so python thinks stdout is not a tty device and uses full buffering
    # We want users to see output in real time so we change to line buffering
    # todo: once python3.7 is supported use .reconfigure() instead
    sys.stdout = TextIOWrapper(open(sys.stdout.fileno(), "wb"), line_buffering=True, encoding=encoding)
Almenon commented 3 years ago

Related issue: https://github.com/Almenon/AREPL-vscode/issues/149

Almenon commented 3 years ago

Damn, that was fast! Nice work!

Duroktar commented 3 years ago

Nice work on the suggested fixes! Saves me a bunch of digging; I really appreciate it :100:

Almenon commented 3 years ago

I tested it and confirmed it's working :)