Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndentationErrors caused by mixed tab/space indents not caught #31

Closed
nedbat opened this issue Nov 15, 2009 · 3 comments
Closed

IndentationErrors caused by mixed tab/space indents not caught #31

nedbat opened this issue Nov 15, 2009 · 3 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Nov 15, 2009

Originally reported by Danek Duvall (Bitbucket: dhduvall, GitHub: dhduvall)


When you have two lines of identical indentation, except that one uses spaces and the other uses tabs (eight spaces to a tabstop), then the tokenize module raises an IndentationError which coverage doesn't catch.

This can be considered a bug in the indentation, but it's only a style bug, as the code works just fine.

This could be considered a bug in tokenize, but I assume it's unlikely to get fixed.

It's a bit of a pain to fix in coverage, I think, because you're seeing it in the looping expression of a for loop. The loop would have to be restructured to pull the tokens from the generator inside the loop, inside a try/except, and either error out usefully (with filename and line number!) or try to go on. Still, it might not be too bad.

The attached file demonstrates the problem.


@nedbat
Copy link
Owner Author

nedbat commented Nov 15, 2009

Actually, I explicitly expandtabs(4) just before tokenizing, so the bug is mine. But I wonder how best to know what size tabs you use? I guess defaulting to 8 is a better choice....

@nedbat
Copy link
Owner Author

nedbat commented Nov 15, 2009

Original comment by Danek Duvall (Bitbucket: dhduvall, GitHub: dhduvall)


We use 8, which seems like the sanest default to me. Most code I see which uses 4-space indent either goes all spaces or mixes spaces and tabs. If there are folks relying on the expandtabs(4) behavior, I suppose you could always add a flag to specify tab width; I dunno.

@nedbat
Copy link
Owner Author

nedbat commented Nov 15, 2009

I'm not sure why I used expandtabs(4), Python is documented as using 8-space tabs: http://docs.python.org/reference/lexical_analysis.html#indentation

Changed to 8-space tabs, and fixed in <<changeset 7a5e06254462 (bb)>>.

@nedbat nedbat closed this as completed Nov 15, 2009
@nedbat nedbat added major bug Something isn't working labels Jun 23, 2018
agronholm added a commit to agronholm/coveragepy that referenced this issue Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant