question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PEP8 and line length

See original GitHub issue

There’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.

  1. 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:closed
  • Created 3 years ago
  • Comments:38 (30 by maintainers)

github_iconTop GitHub Comments

1reaction
PgBielcommented, Jul 7, 2020

not sure; if it is possible to set a “hard limit” as well, then that could be good

0reactions
eulertourcommented, Jul 16, 2020

Looks like it

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Why does PEP-8 specify a maximum line length of 79 ...
Black formats at 120 if you tell it to. PEP-8 also says "it is okay to increase the line length limit up to...
Read more >
PEP 8 – Style Guide for Python Code
Maximum Line Length ... Limit all lines to a maximum of 79 characters. For flowing long blocks of text with fewer structural restrictions...
Read more >
Pep8 line length at 80 is very strange : r/Python - Reddit
The 80 char line limit of pep8 is probably one of the most contentious points. It's notable for being one of the only...
Read more >
Python Style Guide - BigchainDB Documentation
PEP8 has some maximum line length guidelines, starting with “Limit all lines to a maximum of 79 characters” but “for flowing long blocks...
Read more >
how to set max-line-length? · Issue #38 · DamnWidget/anaconda
its exist pep8 --max-line-length option that allow to set max line length i.e. 120. default it is set to 79. i know this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found