[issue22498] frozenset allows modification via -= operator

2014-09-25 Thread James Paget

New submission from James Paget:

The operator -= modifies a frozenset (this should not be possible),
instead of signaling a TypeError.  Contrast with the += operator.

 f=frozenset([1,2])
 f
frozenset([1, 2])
 f -= frozenset([1])
 f
frozenset([2])
 f -= frozenset([2])
 f
frozenset([])
 f += frozenset([2])
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unsupported operand type(s) for +=: 'frozenset' and 'frozenset'


--
components: Interpreter Core
messages: 227557
nosy: James.Paget
priority: normal
severity: normal
status: open
title: frozenset allows modification via -= operator
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22498
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22498] frozenset allows modification via -= operator

2014-09-25 Thread Ezio Melotti

Ezio Melotti added the comment:

This doesn't modify f, it replaces it with a new frozenset:
   f = frozenset({1, 2})
   f
  frozenset({1, 2})
   id(f)
  3071990668
   f -= frozenset({1})
   f
  frozenset({2})
   id(f)
  3066719340
Notice how the two ids are different.

In other words,
  f -= frozenset({1})
is equivalent to
  f = f - frozenset({1})

You get an error with += because
  f = f + frozenset({1})
is not a valid operation for (frozen)sets.

--
nosy: +ezio.melotti
resolution:  - not a bug
stage:  - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22498
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com