ipython/ipython — Issue #1109: timeit with string ending in space gives "ValueError: No closing quotation"
Author: jonovik
Created: 2011-12-06 17:21:44+00:00
State: open

%timeit gives a spurious "No closing quotation" error if the statement to be timed contains a parenthesis with a string ending in space.

```
Microsoft Windows [Versjon 6.1.7601]
Python 2.7.2 |EPD 7.1-1 (32-bit)| (default, Jul 3 2011, 15:13:59) [MSC v.1500 32 bit (Intel)]
IPython 0.11 -- An enhanced Interactive Python.

In [1]: timeit " "
100000000 loops, best of 3: 17.8 ns per loop

In [2]: timeit "a "
100000000 loops, best of 3: 17.7 ns per loop

In [3]: timeit "a"
100000000 loops, best of 3: 17.7 ns per loop

In [4]: timeit ("a")
100000000 loops, best of 3: 18.9 ns per loop

In [5]: timeit ("a ")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
C:\Users\jonvi\ in ()
----> 1 get_ipython().magic(u'timeit ("a ")')

C:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in magic(self, arg_s, next_input)
1892 self._magic_locals = sys._getframe(1).f_locals
1893 with self.builtin_trap:
-> 1894 result = fn(magic_args)
1895 # Ensure we're not keeping object references around:

1896 self._magic_locals = {}

C:\Python27\lib\site-packages\IPython\core\magic.pyc in magic_timeit(self, parameter_s)
1826
1827 opts, stmt = self.parse_options(parameter_s,'n:r:tcp:',
-> 1828 posix=False)
1829 if stmt == "":
1830 return

C:\Python27\lib\site-packages\IPython\core\magic.pyc in parse_options(self, arg_str, opt_str, *long_opts, **kw)
267 # If the list of inputs only has 0 or 1 thing in it, there's no

268 # need to look for options

--> 269 argv = arg_split(arg_str,posix)
270 # Do regular option processing

271 try:

C:\Python27\lib\site-packages\IPython\utils\process.pyc in arg_split(s, posix)
121 lex = shlex.shlex(s, posix=posix)
122 lex.whitespace_split = True
--> 123 tokens = list(lex)
124 if is_unicode:
125 # Convert the tokens back to unicode.

C:\Python27\lib\shlex.pyc in next(self)
267
268 def next(self):
--> 269 token = self.get_token()
270 if token == self.eof:
271 raise StopIteration

C:\Python27\lib\shlex.pyc in get_token(self)
94 return tok
95 # No pushback. Get a token.

---> 96 raw = self.read_token()
97 # Handle inclusions

98 if self.source is not None:

C:\Python27\lib\shlex.pyc in read_token(self)
170 print "shlex: I see EOF in quotes state"
171 # XXX what error should be raised here?

--> 172 raise ValueError, "No closing quotation"
173 if nextchar == self.state:
174 if not self.posix:

ValueError: No closing quotation
```