PEP8 and line length
See original GitHub issueThere’s the intent and a PR #172 flying around to use an autopep8 library to automatically format the code into PEP8 guidelines. I want to have a discussion about two things relating to this PEP8 implementation, both relating to line length specifically.
- By default the PEP8 line length is 79 for code and 72 for docstrings/comments. The question is, do we actually want it that restrictively short? According to official PEP8 guidelines extending code length up to 99 is just fine. For more context, this small 79 characters limit means it’ll even try to split up lines like this one in main.py
spec = importlib.util.spec_from_file_location(module_name, file_name)
spec = importlib.util.spec_from_file_location(
module_name, file_name)
2. Whatever the line length is, there is still an issue with autopep8 we need to be aware of when contributing. Example:
logger.warning("FadeOutAndShiftDown is deprecated and will eventually disappear. Please use FadeOutAndShift(<mobject>, direction=DOWN, <other_args>) instead.")
Adding long strings like that in “String” format only leads autopep8 to throw the whole string down like:
logger.warning(
"FadeOutAndShiftDown is deprecated and will eventually disappear. Please use FadeOutAndShift(<mobject>, direction=DOWN, <other_args>) instead.")
Which doesn’t really get us anywhere. The line is still far too long, and isn’t really more readable either. Similarly it also keeps formats like:
raise Exception(
"ChangingDecimal can only take "
"in a DecimalNumber"
)
Which I think doesn’t look are read too great either. In order to actually keep with the line lengths we’ll have to either go with multiple “String” lines, or what I think looks best, just directly use “”“String”“” for stuff that’s otherwise too long, which I hope autopep8 can work with as well.
raise ValueError("""ArcBetweenPoints called with a radius that is
smaller than half the distance between the points.""")
(Although I suppose the indent of the second line would have to be different.)
As for 1, I’m fairly strongly opposed to having the code line length at a measly 79, and would instead opt for the far more reasonable 99. Despite official PEP8 specifications wanting docstrings/comments at 72 explicitly, I see no reason not to raise their character limit as well, though I’m not as partial there.
Issue Analytics
- State:
- Created 3 years ago
- Comments:38 (30 by maintainers)

Top Related StackOverflow Question
not sure; if it is possible to set a “hard limit” as well, then that could be good
Looks like it