Is there a way to either:
- Always have
-tenabled by default (warn about inconsistent tab usage) - Be able to enable it programmatically on startup (eg. in a
sitecustomize.pymodule)
It would need to work for embedded Python too (so aliasing python or similar solutions will be of no use). Use of sitecustomize.py allows us to hook into embedded Python instances, so this seems like a good place for it.
I thought the warnings module would provide a way to turn this warning on but I don’t see anything.
For reference:
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
...
-t : issue warnings about inconsistent tab usage (-tt: issue errors)
...
Any suggestions on how this might be done?
Thanks.
The only solution I was able to come to involves import hooks. While this is somewhat beyond what I’d hoped to have to do, I felt it was a good excuse for me to learn how they work.
This solution doesn’t check for “inconsistent whitespace” it just checks for tabs, but it would be easy to extend.
Here is the result:
Importing this file (replacing
->|with a literal tab):Yields this output: