[issue40670] supplying an empty string to timeit causes an IndentationError

2021-05-18 Thread Irit Katriel


Change by Irit Katriel :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-09-22 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 557b9a52edc4445cec293f2cc2c268c4f564adcf by Serhiy Storchaka in 
branch 'master':
bpo-40670: More reliable validation of statements in timeit.Timer. (GH-22358)
https://github.com/python/cpython/commit/557b9a52edc4445cec293f2cc2c268c4f564adcf


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-09-22 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
pull_requests: +21396
pull_request: https://github.com/python/cpython/pull/22358

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-09-22 Thread Irit Katriel


Change by Irit Katriel :


--
assignee:  -> docs@python
components: +Documentation
nosy: +docs@python
type:  -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-06-12 Thread Roundup Robot


Change by Roundup Robot :


--
nosy: +python-dev
nosy_count: 6.0 -> 7.0
pull_requests: +20024
pull_request: https://github.com/python/cpython/pull/20830

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-24 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

I intended to say that the current behavior would be less puzzling if the doc 
were changed as I suggest.  I think that a doc change would be sufficient.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-23 Thread Florian Dahlitz


Florian Dahlitz  added the comment:

@terry.reedy sorry if I misunderstood you, but it seems to me that you agree 
with the proposed changes?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-23 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions: +Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-22 Thread Terry J. Reedy

Terry J. Reedy  added the comment:

Let a wcs be a string consisting of only whitespace and comments.
compile(wcs, '', 'exec') treats wcs the same as 'pass'.
Hence, a file with only whitespace and comments is the same as 'pass'.
compile(wcs, '', 'single'), for whatever reason, raises
SyntaxError: unexpected EOF while parsing
To get around this, a wcs input into IDLE's Shell, compiles with 'single', is 
replaced with 'pass' in codeop._maybe_compile, line 76.  I presume the REPL 
does the same.

If one thinks of parameter stmt as a top-level statement (or statements), it is 
reasonable to expect '' to be the same as 'pass'.  If one knows that stmt will 
be embedded into a compound statement (whether 'while', 'for' or 'def' does not 
matter here) for repeated execution, then 'pass' is more obviously the minimal 
statement.

It would have been better if the parameter name were 'suite', as suites can 
never be only whitespace.  We cannot change this, but I suggest replacing

The constructor takes a statement to be timed, an additional statement used for 
setup, and a timer function. Both statements default to 'pass'; the timer 
function is platform-dependent (see the module doc string). stmt and setup may 
also contain multiple statements separated by ; or newlines, as long as they 
don’t contain multi-line string literals. 

with the shorter, clearer, and updated

The constructor takes suite of statement to be timed, an additional suite used 
for setup, and a timer function (default time.perf_counter). Both suites 
default to 'pass' and may not contain multi-line string literals.

Since 3.3, the default timer is platform-independent, at least from a user 
viewpoint, and not mentioned in timeit.__doc__.  Suites can always have 
multiple statments separated by ; and \n.  The only needed qualification is the 
default and the restriction.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-22 Thread Rahul Kumaresan


Change by Rahul Kumaresan :


--
nosy:  -rahul-kumi

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-21 Thread Florian Dahlitz


Florian Dahlitz  added the comment:

I see your point and agree with you. However, IMHO the CLI and the direct 
function call should behave the same way to not confuse users. The opened PR 
ensures that.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-21 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Accepting an empty string in CLI is just an artifact of the implementation.  
There was no intention to support it. It will fail if pass a space:

./python -m timeit ' '

or two empty arguments:
IndentationError:
./python -m timeit '' ''

I do not see this is an issue. Garbage in -- garbage out. IndentationError is a 
subclass of SyntaxError, so if you handle it programmatically, it does not 
matter.

Of course we try to catch some user errors and provide informative traceback. 
timeit now correctly handles most of code which interferes with the control 
flow in functions and loops: 'return', 'yield', 'break', 'await'.

But it is still possible to bypass the validation. For example:

./python -m timeit -s 'while False:' -s 'pass' 'break'

I think there is an infinite number of ways to fool timeit. And an empty string 
is just one of them, not special enough to add a special handling in the code.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-21 Thread Florian Dahlitz


Change by Florian Dahlitz :


--
keywords: +patch
pull_requests: +19560
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/20286

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-21 Thread Florian Dahlitz


Florian Dahlitz  added the comment:

Calling timeit from command-line with the empty string defaults to 'pass'. I 
suggest to adopt this behaviour for calling timeit.timeit in the REPL as 
@edison.abahurire already suggested. I would be happy to submit a PR for it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-21 Thread Florian Dahlitz


Change by Florian Dahlitz :


--
nosy: +DahlitzFlorian

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-20 Thread Edison Abahurire


Edison Abahurire  added the comment:

Yes, This is unexpected

In the first case:
Supplying an empty string can also mean no code has been supplied. So it could 
be better treated as 'pass'.

In the second case:
 Error messages are meant to inform you of what you have done wrong so that you 
fix it. I think raising an Indentation error is far from what a user who is 
calling that method would be expecting, it does not help them at-all.

In the third case:
Supplying an empty string to timeit directly in bash ```python -m timeit '' ``` 
raises no such error. so we could say that fixing this will align the behavior 
in the two ways the function is run to be the same.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-18 Thread Rahul Kumaresan


Change by Rahul Kumaresan :


--
nosy: +rahul-kumi

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-18 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

Is this different than what you would expect?

Supplying garbage to timeit will result in an error:

>>> from timeit import timeit
>>> timeit('weofinwofinwe')
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/timeit.py", 
line 232, in timeit
return Timer(stmt, setup, timer, globals).timeit(number)
  File 
"/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/timeit.py", 
line 176, in timeit
timing = self.inner(it, self.timer)
  File "", line 6, in inner
NameError: name 'weofinwofinwe' is not defined


If you want to time an empty loop, you can use:

>>> timeit('pass', number=1)
0.000104323021822

--
nosy: +remi.lapeyre

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40670] supplying an empty string to timeit causes an IndentationError

2020-05-18 Thread Edison Abahurire


New submission from Edison Abahurire :

The Error can be evidenced below:

```
>>>
>>> import timeit
>>>
>>> timeit.timeit('', number=1)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.8/timeit.py", line 232, in timeit
return Timer(stmt, setup, timer, globals).timeit(number)
  File "/usr/lib/python3.8/timeit.py", line 131, in __init__
code = compile(src, dummy_src_name, "exec")
  File "", line 7
_t1 = _timer()
^
IndentationError: expected an indented block
>>>
```

--
messages: 369208
nosy: anthonypjshaw, edison.abahurire
priority: normal
severity: normal
status: open
title: supplying an empty string to timeit causes an IndentationError

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com