-1

what has changed from python2 to python3 with frozenset?

I noticed this different behaviour: Python2:

>>> a=frozenset()
>>> a
frozenset([])

Python3

>>> a= frozenset()
>>> a
frozenset()

And also:

Python2

>>> a=frozenset((1,2,3))
>>> a
frozenset([1,2,3])

Python3

>>> a=frozenset((1,2,3))
>>> a
frozenset({1,2,3})

Why that? Thanx

asdf
  • 685
  • 7
  • 23
  • The repr changed sightly, where's the problem? – Andrea Corbellini Jan 18 '16 at 13:00
  • Never said that there is one, just wanted to know more. – asdf Jan 18 '16 at 23:10
  • 1
    `frozenset([1,2,3])` became `frozenset({1,2,3})` because `{...}` is the relatively new syntax for sets (it's available in python 2.6 too, but changing the repr in python 2.x would mean breaking compatibility); `frozenset([])` became `frozenset()` because it's shorter and because `frozenset({})` would be inconsistent. – Andrea Corbellini Jan 19 '16 at 10:48

1 Answers1

2

This question would be better directed, for instance, to python.org's python-list, and might yet be reasonably closed. But I will mention two things.

First, representations, like exception messages, are intentionally not part of the language definition. Nonetheless, we core developers are conservative about changing them, and nearly always only for new versions. The gain must be worth the pain of breaking code, even when the code depends on features specified as not to be depended on.

2.7 came out after 3.0, which cam out after 2.6. So if the new reps are in 3.0, which I am going to presume here, then the first question is why the change from 2.6 to 3.0. The answer would be that the new reps are clearly better and 3.0, having been defined as a release that would break more than usual, would be a good time to make the change. The second question would be why not backport to 2.7? Because the change was not that urgent, and of insufficient gain for people sticking with 2.x.

Second, sets were originally introduced as an imported Set. I forget whether there was also a FrozenSet class. Either way, the set and frozenset reps may have been based on their predecessors.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52