Unfortunately my problem is the opposite one - trying to emulate what compile does for IronPython rather than just trying to make some code compile. So adding newlines doesn't help me.
But this case isn't really that important - it was just a wacky corner case I ran into while trying to get other behavior right. I think I can safely ignore this one especially if it's just a bug. > -----Original Message----- > From: gvanros...@gmail.com [mailto:gvanros...@gmail.com] On Behalf Of > Guido van Rossum > Sent: Friday, May 29, 2009 7:20 PM > To: Dino Viehland > Cc: Robert Kern; python-dev@python.org > Subject: Re: [Python-Dev] Indentation oddness... > > I usually append some extra newlines before passing a string to > compile(). That's the usual work-around. There's probably a subtle bug > in the tokenizer when reading from a string -- if you find it, please > upload a patch to the tracker! > > --Guido > > On Fri, May 29, 2009 at 5:52 PM, Dino Viehland <di...@microsoft.com> > wrote: > >> The 'single' mode, which is used for the REPL, is a bit different > than > >> 'exec', > >> which is used for modules. This difference lets you insert "blank" > >> lines of > >> whitespace into a function definition without exiting the definition. > >> Ending > >> with a truly empty line does not cause the IndentationError, so the > >> REPL can > >> successfully compile the code, signaling that the user has finished > >> typing the > >> function. > > > > Sorry, I probably should have mentioned this but it repros w/ > > compile(..., "exec") as well: > > > >>>> code = "def Foo():\n\n pass\n\n " > >>>> compile(code, 'foo', 'exec') > > Traceback (most recent call last): > > File "<stdin>", line 1, in <module> > > File "foo", line 5 > > > > IndentationError: unindent does not match any outer indentation level > > > > It also repros when passing in PyCF_DONT_IMPLY_DEDENT for flags under > > single and exec. > > _______________________________________________ > > Python-Dev mailing list > > Python-Dev@python.org > > http://mail.python.org/mailman/listinfo/python-dev > > Unsubscribe: http://mail.python.org/mailman/options/python- > dev/guido%40python.org > > > > > > -- > --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com