It seems pretty trivial to create your own push utility function:
APPEND = "append"
ADD = "add"
def push(pushable, value):
try:
(getattr(t:=type(pushable), APPEND, None) or getattr(t, ADD))
(pushable, value)
except AttributeError:
raise TypeError(f"{t.__qualname__} object has no attributes
{APPEND} or {ADD}")
The benefits of the core language keeping the usage of sets and lists
utterly separate has been demonstrated over and over again. Bringing them
together at the language feature level definitely seems like a mistake.
---
Ricky.
"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
On Sun, Oct 13, 2019 at 3:24 PM Steve Jorgensen <[email protected]> wrote:
> Failing fast is good, but it is also a very common case to want to add an
> item to a collection regardless of whether it is set-like or sequence-like.
>
> Does the fact that the `append` and `add` methods would still exist
> mitigate your objection? Call `append` when expecting a list, call `add`
> when expecting a set, or call `push` or use `<<` when either of those would
> be appropriate targets.
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/UMCYJRIOZHHCUSVUXY7GLRRP5WIFWOU5/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/KQAAGRKIRVV4MMSRUHI34NPAOWBNPFPI/
Code of Conduct: http://python.org/psf/codeofconduct/