[issue26973] Dict View binops permit non-set types

2016-05-08 Thread R. David Murray

R. David Murray added the comment:

In any case I think the backward compatibility argument torpedoes making the 
views more restrictive.

Since you agree there's no real consensus on python-ideas, I'm going to close 
this.  If there is some other consistency change that seems to make sense and 
gains consensus on python-ideas, you can open another issue.

--
nosy: +r.david.murray
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue26973] Dict View binops permit non-set types

2016-05-08 Thread Joshua Morton

Joshua Morton added the comment:

There (seemed to be) consensus between the one or two on topic commenters that 
something was off, although much of the discussion was on a tangent. Although 
on looking back, there was even less discussion than I originally thought. Heh.

My response was going to be very different, however I did some additional 
digging: the `collections.abc.Set` class can be used as a mixin for 
implementing set-likes. In its default implementations of the various binops, 
they will attempt to convert the right hand argument of an operator to the 
correct type, via _from_iterable. This in effect makes the set the special case 
that is more permissive than Set is. 

This strikes me as strange, I'd expect set and Set to be 'the same', or in 
other words a Set to act like a set and vice versa. But it seems that python 
swings toward your intuition and not mine. And the opposite, making set *more* 
permissive also doesn't sit well, nor does it feel necessary.

--

___
Python tracker 

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



[issue26973] Dict View binops permit non-set types

2016-05-08 Thread Steven D'Aprano

Steven D'Aprano added the comment:

On Sun, May 08, 2016 at 04:24:59AM +, Joshua Morton wrote:

> Following the comments in python ideas [1] [...]
> 
> [1] https://mail.python.org/pipermail/python-ideas/2016-April/039469.html

Am I missing something? I don't see anything resembling a consensus that 
the behaviour of dict views is a bug in that thread, in fact I hardly 
see any discussion about this specific behaviour. (Other related topics 
are discussed in more depth.)

I don't think it is a bug for views to permit non-set arguments with 
binops:

py> {'a': 1, 'b': 2}.keys() & ['a', 'c']
{'a'}

I think it is a matter of taste. My own taste tells me that sets should 
be more restrictive, only accepting other [frozen]sets or subclasses, 
but views should be less restrictive, and perform more duck-typing of 
"set-like" objects, including lists. No, I can't justify it, except by 
an appeal to status quo: that's how it is now, and I don't think that 
changing it is worth breaking backwards compatibility.

--
nosy: +steven.daprano

___
Python tracker 

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



[issue26973] Dict View binops permit non-set types

2016-05-07 Thread Joshua Morton

New submission from Joshua Morton:

Following the comments in python ideas [1], I'm submitting a bug report. In 
python 3, dictionary views (KeysView and ItemsView specifically) do not adhere 
to the same interface as Sets. Specifically, the __and__, __or__, __xor__, and 
__sub__ methods on Views will accept a non-set type (`{}.keys() | []`), while 
the same throws a TypeError on a Set. The suggested, not-backwards-compatible 
solution, was to have dictviews raise errors in the same way. 

[1] https://mail.python.org/pipermail/python-ideas/2016-April/039469.html

--
messages: 265110
nosy: Joshua Morton
priority: normal
severity: normal
status: open
title: Dict View binops permit non-set types
type: behavior
versions: Python 3.4, Python 3.5

___
Python tracker 

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