[issue30100] WeakSet should all discard and remove on items that can have weak references

Serhiy Storchaka report at bugs.python.org
Wed Apr 19 07:48:27 EDT 2017


Serhiy Storchaka added the comment:

The argument for not raising TypeError for unsupported types:

This is just from the definition of a set. If the set can't contain the value of specific type, then checking if this value is contained in the set should return False, and discarding it from the set should be no-op.

The argument for raising TypeError for unsupported types:

Using a value of unsuitable type is likely a programming error. Silencing TypeError can hide an error. Since raising and catching an exception is costly (but it is cheaper in C than in Python), this also can lead to performance degradation which is hard to catch.

If the first argument is stronger then the second argument then we should change a number of set, dict, dict views and OrderedDict methods and make them returning a reasonable result rather than raising TypeError.

If the second argument is stronger then the first argument then we should change just WeakSet.__contains__() and dict.pop(). Since this is a behavior change that can break third-party code they should first emit deprecation warnings for one or two releases.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30100>
_______________________________________


More information about the Python-bugs-list mailing list