[Python-ideas] .pyu nicode syntax symbols (was Re: Empty set, Empty dict)

Andrew Barnert abarnert at yahoo.com
Tue Jul 1 02:27:55 CEST 2014


On Monday, June 30, 2014 5:18 PM, Paul Tagliamonte <paultag at gmail.com> wrote:


[snip]

>Right, so, this was brought up before, but with Hylang
>(https://github.com/hylang/hy), we abuse the PEP 302 new import hooks to
>search sys.path for .hy files rather then .py files.
>
>You could do the same for your .pyu files (again, *without* the blessing
>of the core team, as this is insane), and do the mangling before passing
>it to the normal internals to turn it into bytecode / AST.
>
>Doing it this way means you won't have to futz with the compiler,
>and you can remain happy.


The reason for needing to futz with the compiler is to generate source code that actually compiles to the bytecode to build an empty set directly, instead of the bytecode to load and call the "set" global.

I agree with both you and Guido that the whole thing is silly, and set() is fine. I also agree with your implied assumption that, even if you needed an empty set literal, having it compile to the same thing as set() would be fine. But those who disagree with both, and really want an empty set literal that compiles to "BUILD_SET 0", cannot have it without futzing with the compiler. So, I'd encourage them to work on making the compiler more futzable (which surely more people would have a use for than the number of people for whom set() is intolerably slow, or unusable because they want to redefine the global).


More information about the Python-ideas mailing list