compile('1\n2\n', '','single') == compile('1\n', '','single').
That is, it ignores the second statement ('2\n'), without offering a way for the caller to detect this.
Considering that 'single' is primarily used to emulate the behaviour of the Python interpreter, most of the time, giving it multiple statements is an impossibility, and so that case doesn't matter and could raise an exception without affecting existing code. For example, the code module meets this description, as do debuggers and such.
However, in cases where it _is_ possible to give the compiler multiple statements, the user should be warned that his input isn't valid, somehow. For example, the following doctest will mysteriously fail, because it was written incorrectly (doctest uses 'single'):
>>> import sys ... sys.stdout.write('foo\n') foo
This is because the second statement in the doctest was silently discarded by compile(). It might not always be clear to users how to fix this, and I think this kind of non-obvious error would exist in any use of 'single' that can in theory involve multiple statements, through user error or program bug. So I'd appreciate it if compile() raised an exception in this case. Perhaps SyntaxError or ValueError.
Devin
Hi, I really would like some feedback on this. Or should I send it to the bug tracker? Was this the wrong place?
Devin
On Wed, Jul 20, 2011 at 10:47 AM, Devin Jeanpierre jeanpierreda@gmail.com wrote:
compile('1\n2\n', '','single') == compile('1\n', '','single').
That is, it ignores the second statement ('2\n'), without offering a way for the caller to detect this.
Considering that 'single' is primarily used to emulate the behaviour of the Python interpreter, most of the time, giving it multiple statements is an impossibility, and so that case doesn't matter and could raise an exception without affecting existing code. For example, the code module meets this description, as do debuggers and such.
However, in cases where it _is_ possible to give the compiler multiple statements, the user should be warned that his input isn't valid, somehow. For example, the following doctest will mysteriously fail, because it was written incorrectly (doctest uses 'single'):
>>> import sys ... sys.stdout.write('foo\n') foo
This is because the second statement in the doctest was silently discarded by compile(). It might not always be clear to users how to fix this, and I think this kind of non-obvious error would exist in any use of 'single' that can in theory involve multiple statements, through user error or program bug. So I'd appreciate it if compile() raised an exception in this case. Perhaps SyntaxError or ValueError.
Devin
Devin Jeanpierre wrote:
Hi, I really would like some feedback on this. Or should I send it to the bug tracker? Was this the wrong place?
I agree, the current behaviour seems wrong to me: errors should never pass silently. If I were you, I would add it to the bug tracker.
Done. Thanks!
Devin
On Sat, Aug 6, 2011 at 9:16 PM, Steven D'Aprano steve@pearwood.info wrote:
Devin Jeanpierre wrote:
Hi, I really would like some feedback on this. Or should I send it to the bug tracker? Was this the wrong place?
I agree, the current behaviour seems wrong to me: errors should never pass silently. If I were you, I would add it to the bug tracker.
-- Steven _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas
It's been suggested that I link the ticket to Python-Ideas. Sorry for not doing so earlier:
http://bugs.python.org/issue12705
Devin
On Sat, Aug 6, 2011 at 9:44 PM, Devin Jeanpierre jeanpierreda@gmail.com wrote:
Done. Thanks!
Devin
On Sat, Aug 6, 2011 at 9:16 PM, Steven D'Aprano steve@pearwood.info wrote:
Devin Jeanpierre wrote:
Hi, I really would like some feedback on this. Or should I send it to the bug tracker? Was this the wrong place?
I agree, the current behaviour seems wrong to me: errors should never pass silently. If I were you, I would add it to the bug tracker.
-- Steven _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas