On 28Feb2021 20:05, Guido van Rossum <[email protected]> wrote:
>I'm trying to shorten this again...
>
>On Sun, Feb 28, 2021 at 5:54 PM Cameron Simpson <[email protected]> wrote:
>> Let's turn this on its head:
>> - what specific harm comes from giving EGs container truthiness for
>> size
>> testing?
>
>For something that's not a pure container, this is an anti-pattern. No
>other subclass of BaseException (that I know of) can ever be falsey, so
>existing code would be forgiven to write "if e:" where "if e is not None:"
>was meant.
I that's how you feel, I'll withdraw my advocacy. I agree it's a
difference.
I'll outline my view below the objections below, but agree to disagree
here - I'm not seeking to convince you any more.
>> - what specific harm comes from returning an empty EG from split on
>> no
>> match instead of None?
>
>It would be an exception. What is raising an empty EG supposed to do?
It'd be rather pointless. It assumes a little care on the person making
it (well, using it where I'd asked subgroup to make it). I guess if
there's a fall through in the except* which reraises, its a burden on
the clause author to check such a contingency. But wouldn't such a
check normally be written:
if eg:
raise
on the presumption that None (falsey) means nothing to raise? And
wouldn't the same code work if eg looks like a container in truthiness?
>> - what specific harm comes from supporting iteration with a caveat
>> about
>> metadata in the docstring, and maybe a recommendation of subgroup?
>
>Iteration is such an easy-to-use API that it would become an attractive
>nuisance -- people would use it regardless of whether it's the right tool
>for the job.
Perhaps. But an easy to use API is normally what one wants. For you,
this is a downside because you hold that it is also usually a poor
choice for this facility. Maybe my use case and habits are unusual.
>> - if I wanted to override subgroup and split to not return None, is
>> that
>> even possible with the current ? i.e. can I make a clean metadata
>> preserved EG from an empty list? For example:
>>
>> eg2 = eg.subgroup(lambda e: False)
>>
>> Does that get me None, or an empty group? If the latter, I can roll my
>> own subclass with my desired features. If not, I can't AFAICT.
>
>It returns None. Writing a subclass that behaves differently than the base
>class will just confuse users who aren't aware of your overrides.
Yeah, a subclass might be misleading. Maybe all I need is a help
function or class.
Cheers,
Cameron Simpson <[email protected]>
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/Z4BM5JR7XQOIXCLW6GCE5N6V5Q72XE7W/
Code of Conduct: http://python.org/psf/codeofconduct/