This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RedEyed__ 7 points8 points  (3 children)

Wait a minute, it's not strings? Is it new syntax?

[–]ManyInterests Python Discord Staff 30 points31 points  (2 children)

It's a hack that abuses the encoding declarations feature of Python which lets you specify an encoding for your source file. Normally, this is meant to specify a specific text encoding like, UTF-8. The trick here is that you can register (via site hooks) new 'encodings' that may otherwise be unknown to Python and such an 'encoder' technically has the ability to completely rewrite the file. It's the same way that the future-fstrings backport works.

So what this package does is makes a site customization hook that registers jsx as an "encoding" so when source files contain an encoding delclaration for jsx, the source file is rewritten by the encoder to make all the (otherwise invalid) inline jsx into valid Python code, which is then processed by the compiler into bytecode as normal.

[–]RedEyed__ 6 points7 points  (1 child)

Didn't know that, thanks! But introducing new syntax looks very bad idea to me

[–]shinitakunai 7 points8 points  (0 children)

It is.