-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set dunder operators too permissive? #3184
Comments
Could you prepare an experimental PR (maybe after #3181 is merged), so interested parties can try this against real world code bases? This way we could better evaluate the impact this change would have (good or bad). |
We have |
That would make sense to me. |
I think I need help here. Current situation in master is. Given:
In contrast
These are the two type variants we see for If I make We could also go pragmatic: |
Similar to #1840
With #3181 I made
KeysView
consistent withSet
but I really think the operators are confusingly permissive.Let's look at them
This should fail because this is always a null operation and thus
a programmer error.
This really should fail because it is unlikely meaningful; the
return type is always an empty set thus it is also not a
Set[str]
Although the assumed union type is correct,
Set[A] & Set[B] => Set[A|B]
just doesn't make sense. The operator can only meaningful be applied to same type sets. What we do here is just a form of plain concat or union.If we look at Sets as just containers without some
properties, we could accept it to construct mixed
type Sets using 'union'. I think it is okay for Python,
the name
union
makes it meaningful, but I maybe never didthat in practice.
Since it adds to the type it is also likely that
the following part of the program catches mistakes.
(But lists don't allow that
[1] + ['2']
although they're reallyarbitrary containers. Except my PR #3183.)
The text was updated successfully, but these errors were encountered: