Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread MRAB
On 2017-12-01 22:46, Steven D'Aprano wrote: On Fri, Dec 01, 2017 at 10:23:37AM -0500, brent bejot wrote: I have found myself implementing something like this before. I was working on a command-line tool with nested sub-commands. Each sub-command would import a script and execute something

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Steven D'Aprano
On Fri, Dec 01, 2017 at 10:23:37AM -0500, brent bejot wrote: > I have found myself implementing something like this before. I was working > on a command-line tool with nested sub-commands. Each sub-command would > import a script and execute something out of it. I ended up moving the >

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Brett Cannon
On Fri, 1 Dec 2017 at 10:11 Neil Schemenauer wrote: > On 2017-12-01, Chris Angelico wrote: > > Can you elaborate on where this is useful, please? > > Introspection tools, for example, might want to look at the module > without executing it. Also, it is a building block to make

Re: [Python-ideas] How assignment should work with generators?

2017-12-01 Thread C Anthony Risinger
On Nov 29, 2017 10:09 PM, "Steven D'Aprano" wrote: > On Thu, Nov 30, 2017 at 11:21:48AM +1300, Greg Ewing wrote: > > > It seems that many people think about unpacking rather > > differently from the way I do. I think the difference > > is procedural vs. declarative. > > > >

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Neil Schemenauer
On 2017-12-01, Chris Angelico wrote: > Can you elaborate on where this is useful, please? Introspection tools, for example, might want to look at the module without executing it. Also, it is a building block to make lazy loading of modules work. As Nick points out, importlib can do this

Re: [Python-ideas] PEP 505 vs matrix multiplication

2017-12-01 Thread Chris Barker
On Fri, Dec 1, 2017 at 6:16 AM, Paul Moore wrote: > > I genuinely don't think these kinds of operators are all that useful > > outside the specific domain of working with semi-structured > > hierarchical data stored in graph databases and document stores like > > MongoDB,

Re: [Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-12-01 Thread Ronald Oussoren
> On 1 Dec 2017, at 12:29, Nick Coghlan wrote: > > On 1 December 2017 at 21:04, Ronald Oussoren wrote: >> The second question is more a design question: what’s the better design, >> having __getdescriptor__ as a class method on classes or as method

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread brent bejot
I have found myself implementing something like this before. I was working on a command-line tool with nested sub-commands. Each sub-command would import a script and execute something out of it. I ended up moving the importing of those little scripts into the functions that called them because

Re: [Python-ideas] Add a dict with the attribute access capability

2017-12-01 Thread Ivan Pozdeev via Python-ideas
On 01.12.2017 1:19, Greg Ewing wrote: Ivan Pozdeev via Python-ideas wrote: I needed to hold an external function reference in an object instance (if I assigned it to an attribute, it was converted into an instance method). No, that only happens to functions stored in *class* attributes,

Re: [Python-ideas] PEP 505 vs matrix multiplication

2017-12-01 Thread Paul Moore
On 1 December 2017 at 13:40, Nick Coghlan wrote: > I genuinely don't think these kinds of operators are all that useful > outside the specific domain of working with semi-structured > hierarchical data stored in graph databases and document stores like > MongoDB,

Re: [Python-ideas] PEP 505 vs matrix multiplication

2017-12-01 Thread Nick Coghlan
On 1 December 2017 at 04:49, Antoine Pitrou wrote: > On Wed, 29 Nov 2017 18:14:36 +1000 > Nick Coghlan wrote: >> >> As far as utility goes, I put it in a similar category to matrix >> multiplication: if you don't need it, you don't need it, but when you

Re: [Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-12-01 Thread Nick Coghlan
On 1 December 2017 at 21:04, Ronald Oussoren wrote: > The second question is more a design question: what’s the better design, > having __getdescriptor__ as a class method on classes or as method on > metaclasses? Either one would work, but a class method appears to be

Re: [Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-12-01 Thread Ronald Oussoren
> On 1 Dec 2017, at 11:32, Nick Coghlan wrote: > > On 1 December 2017 at 19:15, Ronald Oussoren wrote: > >> Maybe, but how would this work with super()? Super walks the MRO of type of >> the instance, but skips the class on the MRO. This is not

Re: [Python-ideas] [Python-Dev] What's the status of PEP 505: None-aware operators?

2017-12-01 Thread Steven D'Aprano
On Thu, Nov 30, 2017 at 08:02:08PM +0300, Ivan Pozdeev via Python-ideas wrote: > My experience with these operators in C# says: > * They do save "more than a few keystrokes". Even more importantly, they > allow to avoid double evaluation or the need for a temporary variable > workaround that

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Nick Coghlan
On 1 December 2017 at 20:17, Steven D'Aprano wrote: > If that's what you mean, then no, I haven't wished for that. Unless I'm > missing something, it seems pointless. When, and why, would I want to > import an empty module? Having access to something along these lines is the

Re: [Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-12-01 Thread Nick Coghlan
On 1 December 2017 at 19:15, Ronald Oussoren wrote: > Maybe, but how would this work with super()? Super walks the MRO of type of > the instance, but skips the class on the MRO. This is not equivalent to > walking the MRO of the second class on the MRO when you use

Re: [Python-ideas] Stub class for Generic to further improve PEP 560

2017-12-01 Thread Ivan Levkivskyi
On 1 December 2017 at 00:34, Ilya Kulakov wrote: > Anyway, my expectation is that going along this way (i.e. removing all > runtime API apart from a necessary minimum) > will give a minor speed-up as compared to PEP 560 at the cost of a > breaking change (even for small

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Steven D'Aprano
On Fri, Dec 01, 2017 at 02:13:37AM -0600, Neil Schemenauer wrote: > I have been working on reducing Python statup time. It would be > nice if there was some way to load a module into memory without exec > of its body code. I'm sure other people have wished for this. I don't understand why you

Re: [Python-ideas] How assignment should work with generators?

2017-12-01 Thread Paul Moore
On 1 December 2017 at 09:48, Kirill Balunov wrote: > Probably, some time ago it was necessary to split this thread into two > questions: > 1. Philosophical question regarding sequences and iterators. In particular, > should they behave differently depending on the

Re: [Python-ideas] How assignment should work with generators?

2017-12-01 Thread Kirill Balunov
2017-11-29 22:33 GMT+03:00 Steve Barnes : > > Just a thought but what about a syntax something along the lines of: > > a, b, *remainder = iterable > > Where remainder becomes the iterable with the first two values consumed > by assigning to a & b. If the iterator has less

Re: [Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-12-01 Thread Ronald Oussoren
> On 1 Dec 2017, at 07:01, Nick Coghlan wrote: > > On 1 December 2017 at 01:23, Ronald Oussoren wrote: >> 1) Last time around Mark Shannon worried that this introduces infinite >> recursion in the language itself (in my crummy summary, please read

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Nick Coghlan
On 1 December 2017 at 18:37, Nick Coghlan wrote: > On 1 December 2017 at 18:13, Neil Schemenauer > wrote: >> I have been working on reducing Python statup time. It would be >> nice if there was some way to load a module into memory without exec

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Nick Coghlan
On 1 December 2017 at 18:13, Neil Schemenauer wrote: > I have been working on reducing Python statup time. It would be > nice if there was some way to load a module into memory without exec > of its body code. I'm sure other people have wished for this. > > Perhaps

Re: [Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Chris Angelico
On Fri, Dec 1, 2017 at 7:13 PM, Neil Schemenauer wrote: > I have been working on reducing Python statup time. It would be > nice if there was some way to load a module into memory without exec > of its body code. I'm sure other people have wished for this. I

[Python-ideas] Provide a way to import module without exec body

2017-12-01 Thread Neil Schemenauer
I have been working on reducing Python statup time. It would be nice if there was some way to load a module into memory without exec of its body code. I'm sure other people have wished for this. Perhaps there could be a new special function, similar to __import__ for this purpose. E.g.