Re: [Python-ideas] (no subject)

2016-11-28 Thread Mariatta Wijaya
I'm +1 to the idea of improving error messages :) (but maybe not to the exact new error messages proposed) Raymond Hettinger touched on this topic during his Pycon Canada keynote, as one of the positive contributions that you can do to cpython. > > Traceback (most recent call last): > > File

Re: [Python-ideas] (no subject)

2016-11-28 Thread victor rajewski
Sorry, I forgot the subject line! On Tue., 29 Nov. 2016, 3:58 pm victor rajewski, wrote: > I teach a computing subject to high school students using Python as our > primary language. One thing that often causes confusion at the start is > error messages/exceptions. I think it would lower entry p

Re: [Python-ideas] (no subject)

2016-11-28 Thread Todd
Although there is certainly room good improvement in the error messages, making error messages that work in all cases is hard. For example, functions are just another kind of variable, and it is possible for arbitrary variables to act like functions. So error messages that try to differentiate bet

Re: [Python-ideas] (no subject)

2016-11-28 Thread Bernardo Sulzbach
On 2016-11-29 02:58, victor rajewski wrote: NameError: name 'reponse' is not defined A better message might be: You're trying to use the value of 'reponse', but that variable hasn't got a value yet. You can give it a value earlier in the code, or it could be a typo. You have a variable called '

[Python-ideas] (no subject)

2016-11-28 Thread victor rajewski
I teach a computing subject to high school students using Python as our primary language. One thing that often causes confusion at the start is error messages/exceptions. I think it would lower entry point quite a bit by making error messages more readable to novices. Recent research found reduced

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 12:14 PM, Steven D'Aprano wrote: > What if I have two files? > > # a.py > try: > import spam > except ImportError: > import ham as spam > > # b.py > try: > import spam > except ImportError: > import cornedbeef as spam > In the same project? Then you already

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 05:46 PM, Random832 wrote: On Mon, Nov 28, 2016, at 15:05, Ethan Furman wrote: Because it is unfriendly. Helpful error messages are a great tool to both beginner and seasoned programmers. There won't be a helpful error message unless the distributor writes one. The purpose o

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Random832
On Mon, Nov 28, 2016, at 15:05, Ethan Furman wrote: > Because it is unfriendly. Helpful error messages are a great tool to > both beginner and seasoned programmers. There won't be a helpful error message unless the distributor writes one. > > A distribution could, for example, include an except

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Steven D'Aprano
On Tue, Nov 29, 2016 at 09:52:21AM +1100, Chris Angelico wrote: > +1, because this also provides a coherent way to reword the try/except > import idiom: > > # Current idiom > # somefile.py > try: > import foo > except ImportError: > import subst_foo as foo Nice, clean and self-explanator

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Steven D'Aprano
On Mon, Nov 28, 2016 at 12:05:01PM -0800, Ethan Furman wrote: > >Honestly, though, I'm not sure of the need for the PEP in general. > >"However, there is as of yet no standardized way of dealing with > >importing a missing standard library module." is simply not true. The > >standardized way of de

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Steven D'Aprano
On Mon, Nov 28, 2016 at 02:32:16PM +, Paul Moore wrote: > Also, and possibly more of an issue, use of the ".missing.py" file > will mean that a user can't provide their own implementation of the > module later on sys.path. I don'rt know if this is a significant issue > on Unix platforms. On Wi

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Brett Cannon
On Mon, 28 Nov 2016 at 14:49 Steve Dower wrote: > On 28Nov2016 1433, Steve Dower wrote: > > On 28Nov2016 1419, Nathaniel Smith wrote: > >> I'd suggest that we additional specify that if we find a > >> foo.missing.py, then the code is executed but -- unlike a regular > >> module load -- it's not a

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Todd
On Mon, Nov 28, 2016 at 6:00 PM, Wolfgang Maier < wolfgang.ma...@biologie.uni-freiburg.de> wrote: > On 28.11.2016 23:52, Chris Angelico wrote: > >> >> +1, because this also provides a coherent way to reword the try/except >> import idiom: >> >> # Current idiom >> # somefile.py >> try: >> impor

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Wolfgang Maier
On 28.11.2016 23:52, Chris Angelico wrote: +1, because this also provides a coherent way to reword the try/except import idiom: # Current idiom # somefile.py try: import foo except ImportError: import subst_foo as foo # New idiom: # foo.missing.py import subst_foo as foo import sys; sy

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 9:19 AM, Nathaniel Smith wrote: > This also suggests that the overall error-handling flow for 'import > foo' should look like: > > 1) run foo.missing.py > 2) if it raises an exception: propagate that > 3) otherwise, if sys.modules["foo"] is missing: raise some variety of >

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Steve Dower
On 28Nov2016 1433, Steve Dower wrote: On 28Nov2016 1419, Nathaniel Smith wrote: I'd suggest that we additional specify that if we find a foo.missing.py, then the code is executed but -- unlike a regular module load -- it's not automatically inserted into sys.modules["foo"]. That seems like it co

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 02:42 PM, Wolfgang Maier wrote: A refined (from my previous post which may have ended up too nested) alternative: instead of triggering an immediate search for a .missing.py file, why not have the interpreter intercept any ModuleNotFoundError that bubbles up to the top without b

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Wolfgang Maier
On 28.11.2016 23:19, Nathaniel Smith wrote: I'd suggest that we additional specify that if we find a foo.missing.py, then the code is executed but -- unlike a regular module load -- it's not automatically inserted into sys.modules["foo"]. That seems like it could only create confusion. And it do

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Steve Dower
On 28Nov2016 1419, Nathaniel Smith wrote: I'd suggest that we additional specify that if we find a foo.missing.py, then the code is executed but -- unlike a regular module load -- it's not automatically inserted into sys.modules["foo"]. That seems like it could only create confusion. And it doesn

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Nathaniel Smith
On Mon, Nov 28, 2016 at 5:28 AM, Tomas Orsava wrote: [...] > Specification > = > > When, for any reason, a standard library module is not to be included with > the > rest, a file with its name and the extension ``.missing.py`` shall be > created > and placed in the directory the module

Re: [Python-ideas] Decorator to avoid a mistake

2016-11-28 Thread Chris Barker
On Mon, Nov 28, 2016 at 1:50 PM, Guido van Rossum wrote: > Also -- the ship has kinda sailed on this - maybe a @not_override would >> make more sense. >> >> Isn't the goal to make sure you don't accidentally override a method? >> saying "I know I'm overriding this" is less useful than "I'm not in

Re: [Python-ideas] Decorator to avoid a mistake

2016-11-28 Thread Guido van Rossum
On Mon, Nov 28, 2016 at 1:44 PM, Chris Barker wrote: > > On Mon, Nov 28, 2016 at 1:37 PM, Guido van Rossum > wrote: > > >> They can, and they @override can be bypassed. I don't see that as a >> condemnation of @overload -- it just means that it's not perfect, which is >> fine with me (given that

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 01:26 PM, Paul Moore wrote: On 28 November 2016 at 21:11, Ethan Furman wrote: One "successful" use-case that would be impacted is the fallback import idiom: try: # this would do two full searches before getting the error import BlahBlah except ImportError: import b

Re: [Python-ideas] Decorator to avoid a mistake

2016-11-28 Thread Chris Barker
On Mon, Nov 28, 2016 at 1:37 PM, Guido van Rossum wrote: > They can, and they @override can be bypassed. I don't see that as a > condemnation of @overload -- it just means that it's not perfect, which is > fine with me (given that we're talking about monkey-patching here). > sure -- but this al

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Chris Barker
On Mon, Nov 28, 2016 at 1:26 PM, Paul Moore wrote: > > One "successful" use-case that would be impacted is the fallback import > > idiom: > > > > try: > > # this would do two full searches before getting the error > > import BlahBlah > > except ImportError: > > import blahblah > > Und

Re: [Python-ideas] Decorator to avoid a mistake

2016-11-28 Thread Guido van Rossum
On Mon, Nov 28, 2016 at 1:32 PM, Chris Barker wrote: > On Mon, Nov 28, 2016 at 10:22 AM, Guido van Rossum > wrote: > > >> At calling time, the subclass' method will be found, and used, and the >>> search stops there -- no way to know if there is one with the same name >>> further up the MRO. >>>

Re: [Python-ideas] Decorator to avoid a mistake

2016-11-28 Thread Chris Barker
On Mon, Nov 28, 2016 at 10:22 AM, Guido van Rossum wrote: > At calling time, the subclass' method will be found, and used, and the >> search stops there -- no way to know if there is one with the same name >> further up the MRO. >> >> This is simply incompatable with a language this dynamic. >>

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Wolfgang Maier
On 28.11.2016 22:26, Paul Moore wrote: On 28 November 2016 at 21:11, Ethan Furman wrote: One "successful" use-case that would be impacted is the fallback import idiom: try: # this would do two full searches before getting the error import BlahBlah except ImportError: import blahbla

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Paul Moore
On 28 November 2016 at 21:11, Ethan Furman wrote: > One "successful" use-case that would be impacted is the fallback import > idiom: > > try: > # this would do two full searches before getting the error > import BlahBlah > except ImportError: > import blahblah Under this proposal, the

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 01:01 PM, Guido van Rossum wrote: On Mon, Nov 28, 2016 at 12:51 PM, Ethan Furman wrote: On 11/28/2016 05:28 AM, Tomas Orsava wrote: Rendered PEP: https://fedora-python.github.io/pep-drafts/pep-A.html Overall +1, but usi

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Guido van Rossum
On Mon, Nov 28, 2016 at 12:51 PM, Ethan Furman wrote: > On 11/28/2016 05:28 AM, Tomas Orsava wrote: > > Rendered PEP: https://fedora-python.github.io/pep-drafts/pep-A.html >> > > Overall +1, but using Guido's #2 option instead for handling *.missing.py > files (searching all possible locations fo

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 05:28 AM, Tomas Orsava wrote: Rendered PEP: https://fedora-python.github.io/pep-drafts/pep-A.html Overall +1, but using Guido's #2 option instead for handling *.missing.py files (searching all possible locations for the module before falling back to the stdlib xxx.missing.py de

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 08:35 AM, Random832 wrote: On Mon, Nov 28, 2016, at 10:51, Tomas Orsava wrote: Could some Windows user please check if compiling Python with the current reference implementation [2] of this PEP indeed generates a `curses.missing.py` file among the stdlib files? If so, we might co

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Ethan Furman
On 11/28/2016 08:38 AM, Guido van Rossum wrote: 2. After exhausting sys.path, search it again just for .missing.py files (or perhaps remember the location of the .missing.py file during the first search but don't act immediately on it -- this has the same effect). - Pro: allows user to insta

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Guido van Rossum
On Mon, Nov 28, 2016 at 11:54 AM, Terry Reedy wrote: > On 11/28/2016 11:38 AM, Guido van Rossum wrote: > >> Overall I think this is a good idea. I have one hit: >> >> It seems that there are two possible strategies for searching the >> .missing.py file: >> >> 1. (Currently in the PEP) search it a

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Terry Reedy
On 11/28/2016 11:38 AM, Guido van Rossum wrote: Overall I think this is a good idea. I have one hit: It seems that there are two possible strategies for searching the .missing.py file: 1. (Currently in the PEP) search it at the same time as the .py file when walking along sys.path. - Pro: pre

Re: [Python-ideas] Decorator to avoid a mistake

2016-11-28 Thread Guido van Rossum
On Mon, Nov 28, 2016 at 10:11 AM, Chris Barker wrote: > Am I missing something? > > Given Python's dynamic nature, there is simply no way to know if a method > is overriding a superclass' method until it is called -- and, now that I > think about it even then you don't know. > > At compile time,

Re: [Python-ideas] Decorator to avoid a mistake

2016-11-28 Thread Chris Barker
Am I missing something? Given Python's dynamic nature, there is simply no way to know if a method is overriding a superclass' method until it is called -- and, now that I think about it even then you don't know. At compile time, none of the superclasses may have the given method. At run time, a

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Guido van Rossum
On Mon, Nov 28, 2016 at 9:14 AM, Nathaniel Smith wrote: > Also note that in Guido's option 2, we only incur the extra fstat calls if > the import would otherwise fail. In option 1, there are extra fstat calls > (and thus disk seeks etc.) adding some overhead to every import. Oh, that's an impor

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Nathaniel Smith
On Nov 28, 2016 8:38 AM, "Guido van Rossum" wrote: > > Overall I think this is a good idea. I have one hit: > > It seems that there are two possible strategies for searching the .missing.py file: > > 1. (Currently in the PEP) search it at the same time as the .py file when walking along sys.path.

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Alexandre Brault
I would also prefer (2) for exactly the example given in this thread. The Windows version of curses.missing.py could raise a ModuleNotFoundError saying that curses is not available on Windows, but a developer who wants to can install PDCurses to implement the stdlib module. I don't think the few c

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Guido van Rossum
Overall I think this is a good idea. I have one hit: It seems that there are two possible strategies for searching the .missing.py file: 1. (Currently in the PEP) search it at the same time as the .py file when walking along sys.path. - Pro: prevents confusion when the user accidentally has the

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Random832
On Mon, Nov 28, 2016, at 10:51, Tomas Orsava wrote: > Could some Windows user please check if compiling Python with the > current reference implementation [2] of this PEP indeed generates a > `curses.missing.py` file among the stdlib files? If so, we might > consider skipping the generation of t

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Paul Moore
On 28 November 2016 at 15:51, Tomas Orsava wrote: > I believe I may have found the Windows curses implementation, it's called > PDCurses [0], and this website [1] appears to be distributing it under the > name `curses`. My apologies, I should have included a pointer. That is indeed the distributi

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Tomas Orsava
On 11/28/2016 03:32 PM, Paul Moore wrote: On 28 November 2016 at 13:28, Tomas Orsava wrote: The ``.missing.py`` extension will be added to the end of the list, and configured to be handled by ``SourceFileLoader``. Thus, if a module is not found in its proper location, the ``XYZ.missing.py`` f

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Paul Moore
On 28 November 2016 at 13:28, Tomas Orsava wrote: > The ``.missing.py`` extension will be added to the end of the list, and > configured to be handled by ``SourceFileLoader``. Thus, if a module is not > found in its proper location, the ``XYZ.missing.py`` file is found and > executed, and further

Re: [Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Chris Angelico
On Tue, Nov 29, 2016 at 12:28 AM, Tomas Orsava wrote: > We have written a draft PEP entitled "Distributing a Subset of the Standard > Library" that aims to standardize and improve how Python handles omissions > from its standard library. This is relevant both to Python itself as well as > to Linux

[Python-ideas] PEP: Distributing a Subset of the Standard Library

2016-11-28 Thread Tomas Orsava
Hi! We have written a draft PEP entitled "Distributing a Subset of the Standard Library" that aims to standardize and improve how Python handles omissions from its standard library. This is relevant both to Python itself as well as to Linux and other distributions that are packaging it, as the