Ethan Furman wrote:
> It seems to me that the appropriate fix is for numpy to have an "is_empty()" 
> function that knows how to deal with arrays 
> and array-like structures, not force every container to grow a new method.

Yes, numpy could and probably should have an "is_empty()" method. However, 
defining a method downstream breaks duck typing and maybe even more important 
authors have to mentally switch between the two empty-check variants `if users` 
and `if users.is_empty()` depending on the context.

Ethan Furman wrote:
> On 8/23/21 1:15 PM, Tim Hoffmann via Python-ideas wrote:
> > If you want to write a function that accepts array-like `values`, you have 
> > to change
> > a check `if values` to `if len(values) == 0`. That works for both but is 
> > against the
> > PEP8 recommendation. This is a shortcoming of the language.
> > Numpy is not Python, but a specialist third-party package that has made 
> > specialist choices about basic operations -- 
> that does not sound like a shortcoming of the language.

The "specialist choices" ``if len(values) == 0` in Numpy are the best you can 
do within the capabilities of the Python language if you want the code to 
function with lists and arrays. For Numpy to do better Python would need to 
either provide the above mentioned "has element-wise operations" protocol or an 
is_empty protocol.

I consider emptiness-check a basic concept that should be consistent and easy 
to use across containers. 

Tim
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7FMYUH7L22LQOIV5EZKW56GFRKFQZQND/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to