Re: [Python-ideas] (no subject)

2016-11-29 Thread Stephen J. Turnbull
Victor Stinner writes: > Using a custom exception handler, you can run expensive functions, > like the feature: "suggest len when length is used". LGTM. > The problem is then when students have to use a Python without the > custom exception handler. Put the exception handler in an

Re: [Python-ideas] Better error messages [was: (no subject)]

2016-11-29 Thread Matthias Bussonnier
There are a couple of project that tried to improved heuristic on some error messages. Two I can think off are: https://github.com/SylvainDe/DidYouMean-Python and https://github.com/dutc/didyoumean I think that better error messages could be implemented only in the repl, and/or by

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

2016-11-29 Thread Nick Coghlan
On 30 November 2016 at 04:33, Brett Cannon wrote: > On Tue, 29 Nov 2016 at 06:49 Nick Coghlan wrote: >> >> On 29 November 2016 at 20:54, Tomas Orsava wrote: >> > With a metapath hook, .missing.py files are probably overkill, and the >> >

[Python-ideas] Better error messages [was: (no subject)]

2016-11-29 Thread Stephen J. Turnbull
Mariatta Wijaya writes: > > NameError: name 'length' is not defined > > > A better message might be: > > > Python doesn't recognise the function "length". Did you mean > > len?' This particular change would be useful to a beginning Python programmer. I've made that error often enough

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

2016-11-29 Thread Eric V. Smith
On 11/29/2016 1:33 PM, Brett Cannon wrote: On Tue, 29 Nov 2016 at 06:49 Nick Coghlan > wrote: On 29 November 2016 at 20:54, Tomas Orsava > wrote: > With a metapath hook, .missing.py files

Re: [Python-ideas] (no subject)

2016-11-29 Thread MRAB
On 2016-11-29 19:45, Brendan Barnwell wrote: On 2016-11-29 09:43, Brett Cannon wrote: One way to make this cheap is to have a reasonable default message and use attributes on the exceptions trigger the use of the default message. Nearly a year ago I filed a bunch of issues for ideas on

Re: [Python-ideas] (no subject)

2016-11-29 Thread Nathaniel Smith
On Nov 29, 2016 9:43 AM, "Brett Cannon" wrote: > > > > On Tue, 29 Nov 2016 at 02:39 Nathaniel Smith wrote: >> >> On Tue, Nov 29, 2016 at 1:05 AM, Victor Stinner >> wrote: >> > Hi, >> > >> > Python is optimized for performance.

Re: [Python-ideas] (no subject)

2016-11-29 Thread Terry Reedy
On 11/29/2016 11:32 AM, Rob Cliffe wrote: On 29/11/2016 04:58, victor rajewski wrote: Traceback (most recent call last): File "foo.py", line 2, in l[10]=14 IndexError: list assignment index out of range A better message might be: You tried to use l[10] when l is only 4 elements

Re: [Python-ideas] (no subject)

2016-11-29 Thread Brendan Barnwell
On 2016-11-29 09:43, Brett Cannon wrote: One way to make this cheap is to have a reasonable default message and use attributes on the exceptions trigger the use of the default message. Nearly a year ago I filed a bunch of issues for ideas on providing attributes on exceptions where it made

Re: [Python-ideas] (no subject)

2016-11-29 Thread Brett Cannon
On Tue, 29 Nov 2016 at 10:28 Nick Timkovich wrote: > I would consider the speed of the "ultimate error handler" (i.e. whatever > prints the traceback and kills the program) in the interpreter to be moot, > so long as it takes a small fraction of a second. Optimizing

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

2016-11-29 Thread Brett Cannon
On Tue, 29 Nov 2016 at 06:49 Nick Coghlan wrote: > On 29 November 2016 at 20:54, Tomas Orsava wrote: > > With a metapath hook, .missing.py files are probably overkill, and the > hook > > can just look at one file (or a static compiled-in list) of > >

Re: [Python-ideas] (no subject)

2016-11-29 Thread Nick Timkovich
I would consider the speed of the "ultimate error handler" (i.e. whatever prints the traceback and kills the program) in the interpreter to be moot, so long as it takes a small fraction of a second. Optimizing Python's speed it crashes super-fast due to an *unhandled* NameError in your program

Re: [Python-ideas] (no subject)

2016-11-29 Thread Chris Barker
On Tue, Nov 29, 2016 at 5:48 AM, Nick Coghlan wrote: > > SyntaxErrors in an inner loop? That seems unlikely to me. > Syntax Errors are a special case, as by definition the code isn't being run yet (yes, there could be an eval in there...) So we could at least make those

Re: [Python-ideas] (no subject)

2016-11-29 Thread Brett Cannon
On Tue, 29 Nov 2016 at 02:39 Nathaniel Smith wrote: > On Tue, Nov 29, 2016 at 1:05 AM, Victor Stinner > wrote: > > Hi, > > > > Python is optimized for performance. Formatting an error message has a > > cost on performances. > > Sure, but we have to look

Re: [Python-ideas] (no subject)

2016-11-29 Thread Rob Cliffe
On 29/11/2016 04:58, victor rajewski wrote: Traceback (most recent call last): File "foo.py", line 2, in l[10]=14 IndexError: list assignment index out of range A better message might be: You tried to use l[10] when l is only 4 elements long. You can add items to l using

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

2016-11-29 Thread Todd
On Tue, Nov 29, 2016 at 4:13 AM, M.-A. Lemburg wrote: > On 29.11.2016 00:50, Brett Cannon wrote: > > Seventh, these *.missing.py files if they are directly executed are > totally > > going to be abused like *.pth files, I can just feel it in my bones. We > > need to be okay with

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

2016-11-29 Thread Todd
On Nov 29, 2016 5:51 AM, "Wolfgang Maier" < wolfgang.ma...@biologie.uni-freiburg.de> wrote: > > On 29.11.2016 10:39, Paul Moore wrote: >> >> On 28 November 2016 at 22:33, Steve Dower wrote: >>> >>> Given that, this wouldn't necessarily need to be an executable file. The

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

2016-11-29 Thread Nick Coghlan
On 29 November 2016 at 20:54, Tomas Orsava wrote: > With a metapath hook, .missing.py files are probably overkill, and the hook > can just look at one file (or a static compiled-in list) of > ModuleNotFound/ImportError messages for all missing modules, as M.-A. > Lemburg and

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

2016-11-29 Thread Nick Coghlan
On 29 November 2016 at 03:28, Guido van Rossum wrote: > 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

Re: [Python-ideas] (no subject)

2016-11-29 Thread Nick Coghlan
On 29 November 2016 at 20:38, Nathaniel Smith wrote: > On Tue, Nov 29, 2016 at 1:05 AM, Victor Stinner > wrote: >> Hi, >> >> Python is optimized for performance. Formatting an error message has a >> cost on performances. > > Sure, but we have to look at

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

2016-11-29 Thread Nick Coghlan
On 29 November 2016 at 08:01, Chris Barker wrote: > 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

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

2016-11-29 Thread Paul Moore
On 29 November 2016 at 10:51, Wolfgang Maier wrote: > On 29.11.2016 10:39, Paul Moore wrote: >> >> On 28 November 2016 at 22:33, Steve Dower wrote: >>> >>> Given that, this wouldn't necessarily need to be an executable file. The

Re: [Python-ideas] (no subject)

2016-11-29 Thread Wes Turner
On Tuesday, November 29, 2016, Wes Turner wrote: > The existing docs for errors and exceptions: > > - https://docs.python.org/2/library/exceptions.html > - https://docs.python.org/3/library/exceptions.html > -

Re: [Python-ideas] (no subject)

2016-11-29 Thread Wes Turner
On Tuesday, November 29, 2016, Nathaniel Smith wrote: > On Tue, Nov 29, 2016 at 1:05 AM, Victor Stinner > > wrote: > > Hi, > > > > Python is optimized for performance. Formatting an error message has a > > cost on performances. > > Sure,

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

2016-11-29 Thread Tomas Orsava
On 11/28/2016 05:38 PM, 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:

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

2016-11-29 Thread Wolfgang Maier
On 29.11.2016 10:39, Paul Moore wrote: On 28 November 2016 at 22:33, Steve Dower wrote: Given that, this wouldn't necessarily need to be an executable file. The finder could locate a "foo.missing" file and raise ModuleNotFoundError with the contents of the file as the

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

2016-11-29 Thread Cory Benfield
> On 29 Nov 2016, at 02:48, Chris Angelico wrote: > > 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: >>

Re: [Python-ideas] (no subject)

2016-11-29 Thread Wes Turner
The existing docs for errors and exceptions: - https://docs.python.org/2/library/exceptions.html - https://docs.python.org/3/library/exceptions.html - https://hg.python.org/cpython/file/tip/Doc/library/exceptions.rst - https://github.com/python/cpython/blob/master/Doc/library/exceptions.rst -

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

2016-11-29 Thread Paul Moore
On 28 November 2016 at 22:33, Steve Dower wrote: > Given that, this wouldn't necessarily need to be an executable file. The > finder could locate a "foo.missing" file and raise ModuleNotFoundError with > the contents of the file as the message. No need to allow/require any

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

2016-11-29 Thread M.-A. Lemburg
On 29.11.2016 00:50, Brett Cannon wrote: > Seventh, these *.missing.py files if they are directly executed are totally > going to be abused like *.pth files, I can just feel it in my bones. We > need to be okay with this if we accept this PEP as-is. Since the purpose of the PEP was to allow

Re: [Python-ideas] (no subject)

2016-11-29 Thread Victor Stinner
Hi, Python is optimized for performance. Formatting an error message has a cost on performances. I suggest you to teach your student to use the REPL and use a custom exception handler: sys.excepthook: https://docs.python.org/2/library/sys.html#sys.excepthook Using a custom exception handler,