Re: [Python-ideas] Add hooks to asyncio lifecycle

2018-06-09 Thread Nick Coghlan
On 10 June 2018 at 07:59, Michel Desmoulin wrote: > What I'm proposing is to make that easy to implement by just letting > anyone put a check in there. > > Overriding policy, loops or tasks factories are usually down for > critical parts of the system. The errors emerging from a bug in there >

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Steven D'Aprano
On Sat, Jun 09, 2018 at 09:17:37AM -0400, Juancarlo Añez wrote: > > Do you mean the context manager semantics of with statements? As in, > > calling the __enter__ and __exit__ method? > > > > No. Just the scope of the variables introduced, which is different in `with > as` and `except as`. They

Re: [Python-ideas] Add hooks to asyncio lifecycle

2018-06-09 Thread Michel Desmoulin
> > IMHO, it is not any framework's job to check for this.  It is a > programmer error.  Not clearing the memory is a programmer error either but a gc helps. Not closing a file either but using `with` help. Not passing the proper type is a programmer error but we have type hints. We even

Re: [Python-ideas] Allow callable in slices

2018-06-09 Thread Nick Coghlan
On 9 June 2018 at 19:20, Michel Desmoulin wrote: > Given 2 callables checking when a condition arises and returning True: > > def starting_when(element): > ... > > def ending_when(element: > ... > Allow: > > a_list[starting_when:] > > To be equivalent to: > > from

Re: [Python-ideas] Trigonometry in degrees

2018-06-09 Thread Michael Selik
On Sat, Jun 9, 2018 at 2:22 AM Adam Bartoš wrote: > The idea was that the functions could handle the PiMultiple instances in a > special way and fall back to float only when a special value is not detected. > It would be like the proposed dsin functionality, but with a magic class > instead

Re: [Python-ideas] Allow callables in slices

2018-06-09 Thread Michael Selik
On Sat, Jun 9, 2018 at 6:28 AM Michel Desmoulin wrote: > Example, open this files, load all lines in memory, skip the first line, > then get all the line until the first comment: > > import itertools > > def is_commented(line): > return lines.startwith('#') > > def lines(): >

Re: [Python-ideas] Add hooks to asyncio lifecycle

2018-06-09 Thread Michel Desmoulin
Le 09/06/2018 à 12:33, Andrew Svetlov a écrit : > If we consistently apply the idea of hook for internal python structure > modification too many things should be changed. Import > machinery, tracemalloc, profilers/tracers, name it. > If your code (I still don't see the real-life example) wants

Re: [Python-ideas] Allow callables in slices

2018-06-09 Thread Michel Desmoulin
Le 09/06/2018 à 11:47, Steven D'Aprano a écrit : > On Sat, Jun 09, 2018 at 11:17:05AM +0200, Michel Desmoulin wrote: >> Such as that: >> >> def starting_when(element): >> ... >> >> a_list[starting_when:] > >> Is equivalent to: > [...] >> list(dropwhile(lambda x: not

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Juancarlo Añez
> Do you mean the context manager semantics of with statements? As in, > calling the __enter__ and __exit__ method? > No. Just the scope of the variables introduced, which is different in `with as` and `except as`. > Please make sure you are very familiar with PEP 572 before you do, and >

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Steven D'Aprano
On Sat, Jun 09, 2018 at 08:43:47AM -0400, Juancarlo Añez wrote: > Hello @here, > > Is there a guide about writing (and publishing) PEPs? https://www.python.org/dev/peps/pep-0001/ > I'd like to write one on `while expre as v: ...` using the context > semantics of `with expr as v` (not `except E

Re: [Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Jeroen Demeyer
On 2018-06-09 14:43, Juancarlo Añez wrote: Is there a guide about writing (and publishing) PEPs? https://www.python.org/dev/peps/pep-0001/ ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas

[Python-ideas] A PEP on introducing variables on 'if' and 'while'

2018-06-09 Thread Juancarlo Añez
Hello @here, Is there a guide about writing (and publishing) PEPs? I'd like to write one on `while expre as v: ...` using the context semantics of `with expr as v` (not `except E as e`). Cheers, ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] Making Path() a built in.

2018-06-09 Thread Steven D'Aprano
On Wed, Jun 06, 2018 at 07:05:35PM +0100, Barry Scott wrote: > I assume the the idea is that everybody has Path available without the need > to do the import dance first. > > If its for personal convenience you can always do this trick, that is used by > gettext to make _ a builtin. > > import

[Python-ideas] Allow callable in slices

2018-06-09 Thread Michel Desmoulin
Given 2 callables checking when a condition arises and returning True: def starting_when(element): ... def ending_when(element: ... Allow: a_list[starting_when:] To be equivalent to: from itertools import dropwhile list(dropwhile(lambda x: not

Re: [Python-ideas] A "within" keyword

2018-06-09 Thread Steven D'Aprano
On Sat, Jun 09, 2018 at 03:07:39PM +1000, Nick Coghlan wrote: > It's doable without code generation hacks by using class statements instead > of with statements. > > The withdrawn PEP 422 shows how to use a custom metaclass to support a > "namespace" keyword argument in the class header that

Re: [Python-ideas] A "within" keyword

2018-06-09 Thread Robert Vanden Eynde
Classes Provide already some features of a namespace : class cool_namespace: A = 8 @staticmethod def f(): return "yo" @staticmethod def g(): return (1 + cool_namespace.A) * cool_namespace.f() And if you're tired of writing @staticmethod, you can write a

Re: [Python-ideas] A "within" keyword

2018-06-09 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 02:41:54PM -0400, David Teresi wrote: > One of the features I miss from languages such as C# is namespaces that > work across files - it makes it a lot easier to organize code IMO. I too have often wanted a sub-module namespace without the need to separate code into

Re: [Python-ideas] Making Path() a built in.

2018-06-09 Thread Michel Desmoulin
Creating built in dynamically is not a good idea. Tools complain, new comers wonder where it comes from, it sets a precedent for adding more or debating about it. Better have the debate once here, make it official or decline it officially, and have a clean result. Le 08/06/2018 à 21:28, Barry a

Re: [Python-ideas] A "within" keyword

2018-06-09 Thread Steven D'Aprano
On Fri, Jun 08, 2018 at 03:07:28PM -0700, Michael Selik wrote: > You can use ``eval`` to run an expression, swapping in a different globals > and/or locals namespace. Will this serve your purpose? > > In [1]: import types > In [2]: ns = types.SimpleNamespace(a=1) > In [3]: eval('a', ns.__dict__)

Re: [Python-ideas] Fwd: New suggested built in keyword: do

2018-06-09 Thread Michael Selik
The benefit of list, dict, and set comprehensions and generator expressions is that they evaluate, as opposed to simply exec. The purpose of making them one-liners is to allow them to be assigned to a variable or passed as an argument. If you're not assigning or passing, then why not use a