[Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-11 Thread Gregory P. Smith
Completely obvious what it does, but it irritates my aesthetic sensibilities every time I see: frozenset({spam, eggs}) Why? Because I assume under the hood that creates a set of spam and eggs before calling frozenset to copy it into a new frozenset object before the original set is garbage colle

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-11 Thread Robert Vanden Eynde
I completely get your pain, the Copy seems like a waste of ressource. However I think making an optimisation on the C-Level is better than introducing the litteral, because Python is a general purpose langauge and most of the appplication don't need frozenset or bytearrays and that would clutter

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-11 Thread Jelle Zijlstra
2018-07-11 16:25 GMT-07:00 Gregory P. Smith : > Completely obvious what it does, but it irritates my aesthetic > sensibilities every time I see: > frozenset({spam, eggs}) > > Why? Because I assume under the hood that creates a set of spam and eggs > before calling frozenset to copy it into a new

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-11 Thread Gregory P. Smith
On Wed, Jul 11, 2018 at 4:45 PM Jelle Zijlstra wrote: > 2018-07-11 16:25 GMT-07:00 Gregory P. Smith : > >> Completely obvious what it does, but it irritates my aesthetic >> sensibilities every time I see: >> frozenset({spam, eggs}) >> >> Why? Because I assume under the hood that creates a set o

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-11 Thread Chris Angelico
On Thu, Jul 12, 2018 at 10:13 AM, Gregory P. Smith wrote: > > On Wed, Jul 11, 2018 at 4:45 PM Jelle Zijlstra > wrote: >> This could be done safely and without too much craziness if .freeze() on a >> set returned a new frozenset. The compiler could then safely optimize {a, >> set, literal}.freeze(

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-11 Thread Robert Vanden Eynde
{1,2,7}.freeze() or {1,2,7}.to_frozenset() seem very natural and if this can be optimized to avoid the copy, it's perfect. For bytearray, one use case would be to optimise bytearray([1,2,7,2]) in something like [1,2,7,2].to_byterray(). About bytes, one could have (1,2,7,2).to_bytes() instead of b

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-11 Thread Guido van Rossum
I know of many use cases for frozenset({...}) and I think a hack along those lines is fine -- but what's the common use for bytearray(b"...") or bytearray((...))? Almost invariably a bytearray is created empty or as a given number of zeros. I certainly wouldn't want to burden the tuple type with a

[Python-ideas] Unicode Name Aliases keyword argument abbreviation in unicodedata.name for missing names

2018-07-11 Thread Robert Vanden Eynde
unicodedata.name raises KeyError for a few unicode characters like '\0' or '\n', altough the documentation is very clear on the implementation, this is often not what people want, ie. a string describing the character. In Python 3.3, the name aliases became accepted in

Re: [Python-ideas] anyone need a frozenset or bytearray literal?

2018-07-11 Thread Gregory P. Smith
On Wed, Jul 11, 2018 at 6:13 PM Guido van Rossum wrote: > I know of many use cases for frozenset({...}) and I think a hack along > those lines is fine -- but what's the common use for bytearray(b"...") or > bytearray((...))? Almost invariably a bytearray is created empty or as a > given number of