[Python-Dev] itertools predicates

2016-11-03 Thread Stephen J. Turnbull
Francisco Couzo writes:

 > I'd be interested in writing a patch to make itertools more consistent if
 > there's a consensus.

I don't understand what you mean by "consistent".  I would argue that
in Python, an argument of None means "use the TOOWTDI default".  For
"filterfalse", bool() is pretty obvious for the default predicate
since most Python classes do have a boolean interpretation.  For
"groupby", I guess the identity is the "intuitive" default.  But for
dropwhile, bool() or the identity seem like obvious choices, but
intuitively they're not very useful since the head of what's left is a
false-y.  When would you want that?  Typically false-ies are "nothing
to see here, people, move along" values.  I guess that consideration
suggest lambda x: not(x), but I don't see why one would want to spell
that dropwhile(None, ...) rather than dropwhile(not, ...), especially
since in many contexts what you might really want (and expect None to
default to) is dropwhile(lambda x: x is None, ...).

Bottom line for me is that this use (and non-use) of None is consistent
with Python practice regarding defaults.

So, "accepts None" vs "doesn't accept None" doesn't seem to me to be
an important enough consistency to impose unobvious semantics on
dropwhile(None, ...).

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] itertools predicates

2016-11-03 Thread Francisco Couzo
Stephen, dropwhile(None, ...) was an example, takewhile(None, ...) doesn't
works either and it makes a lot of sense IMO.

On Thu, Nov 3, 2016 at 7:07 AM, Stephen J. Turnbull <
turnbull.stephen...@u.tsukuba.ac.jp> wrote:

> Francisco Couzo writes:
>
>  > I'd be interested in writing a patch to make itertools more consistent
> if
>  > there's a consensus.
>
> I don't understand what you mean by "consistent".  I would argue that
> in Python, an argument of None means "use the TOOWTDI default".  For
> "filterfalse", bool() is pretty obvious for the default predicate
> since most Python classes do have a boolean interpretation.  For
> "groupby", I guess the identity is the "intuitive" default.  But for
> dropwhile, bool() or the identity seem like obvious choices, but
> intuitively they're not very useful since the head of what's left is a
> false-y.  When would you want that?  Typically false-ies are "nothing
> to see here, people, move along" values.  I guess that consideration
> suggest lambda x: not(x), but I don't see why one would want to spell
> that dropwhile(None, ...) rather than dropwhile(not, ...), especially
> since in many contexts what you might really want (and expect None to
> default to) is dropwhile(lambda x: x is None, ...).
>
> Bottom line for me is that this use (and non-use) of None is consistent
> with Python practice regarding defaults.
>
> So, "accepts None" vs "doesn't accept None" doesn't seem to me to be
> an important enough consistency to impose unobvious semantics on
> dropwhile(None, ...).
>
>
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Parsing f-strings from PEP 498 -- Literal String Interpolation

2016-11-03 Thread Fabio Zadrozny
Hi Python-Dev,

I'm trying to get my head around on what's accepted in f-strings --
https://www.python.org/dev/peps/pep-0498/ seems very light on the details
on what it does accept as an expression and how things should actually be
parsed (and the current implementation still doesn't seem to be in a state
for a final release, so, I thought asking on python-dev would be a
reasonable option).

I was thinking there'd be some grammar for it (something as
https://docs.python.org/3.6/reference/grammar.html), but all I could find
related to this is a quote saying that f-strings should be something as:

f '  {} 

So, given that, is it safe to assume that  would be equal to
the "test" node from the official grammar?

I initially thought it would obviously be, but the PEP says that using a
lamda inside the expression would conflict because of the colon (which
wouldn't happen if a proper grammar was actually used for this parsing as
there'd be no conflict as the lamda would properly consume the colon), so,
I guess some pre-parser steps takes place to separate the expression to
then be parsed, so, I'm interested on knowing how exactly that should work
when the implementation is finished -- lots of plus points if there's
actually a grammar to back it up :)

Thanks,

Fabio
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] itertools predicates

2016-11-03 Thread Steven D'Aprano
On Wed, Nov 02, 2016 at 07:03:27PM -0300, Francisco Couzo wrote:
> Some functions that take a predicate from itertools accept None as its
> predicate:
[...]
> I'd be interested in writing a patch to make itertools more consistent if
> there's a consensus.

There's a line in PEP 8 about foolish consistency. Consistency just for 
the sake of consistency is not a virtue.

I have no objection to adding support for None to individual itertools 
functions on the basis that it makes sense for that function. If you can 
suggest a reasonable and *useful* default predicate or key function to 
use for None, then sure, add it to the tracker as a feature enhancement. 
(And, of course, a patch would be appreciated.)

But that will be because it is a useful enhancement, not because of 
"consistency". 


> I see two possible solutions:

Before there can be a solution, there first has to be a problem that 
needs solving. "Lack of consistency" is not necessarily a problem. The 
intertools functions are quite different, they do different things with 
different APIs. The question here should not be "why don't these 
functions take None as an argument?", rather it should be "why should 
these functions take None as an argument?".



-- 
Steve
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Implementing (parts of) copy module in C

2016-11-03 Thread Rasmus Villemoes
On Wed, Nov 02 2016, "Stephen J. Turnbull" 
 wrote:

>  > Where/how should RFC patches be posted?
>
> To the issue tracker, bugs.python.org.  A follow-up here (and if you
> choose to post to python-list, there) to mention the issue number and
> URL is a good idea.

Thanks. Turns out to be a lot easier to forward-port than I feared, so
I've put an RFC at .

Rasmus

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com