[Python-ideas] Keyword/Symbol literals

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Jan 21 20:11:36 CET 2015

On Wed, Jan 21, 2015 at 12:42 PM, Guido van Rossum <guido at python.org> wrote:

> There's no way adding something like this today will suddenly change
> everything else that is part of having "symbols"; the proposed feature
> would be lacking the integration with the internals that makes it work well
> in some other languages.

Wouldn't it be possible to simply have

def Symbol(str):
    def __new__(cls_, *args):
        istr = sys.intern(str(*args))
        return str.__new__(cls, istr)

and have sys.intern() return Symbol instances at some point?  I don't see
any obvious compatibility problems.

How would this be different from adding bool as a subclass of int some time

BTW, I think Pandas found [1] the way to have memory-saving string vectors
without having a symbol type in the core.

[1] http://pandas-docs.github.io/pandas-docs-travis/categorical.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150121/e1f57abe/attachment.html>

More information about the Python-ideas mailing list