Pycodestyle: Disable 'line too long' checks just for shebang line?

Created on 23 Mar 2018  路  7Comments  路  Source: PyCQA/pycodestyle

Feature request: I would like to not disable E501, but ignore it just for a shebang line (if present). E.g. if the first line of the file starts with #!, don't check for E501, otherwise act as normal?

I posted about this on stackoverflow:

So if the max line length is 5 (for sake of example), with this file:

#!/run/stuff
x=3
print(x)

They should complain about the third line but not the first one.

But with this file:

x = 1 + 1 + 1
# Print the result
print(x)

It should complain about all three lines.

feature needs patch

Most helpful comment

@jfhc Oh neat! I didn't know you could do that.

Got my vote then.

All 7 comments

I don't have a strong opinion either way, but I'm quite curious what shebang lines would run into the line length limit. Is it just that the python executable's path is especially verbose, or is there more to shebangs than I know?

edit: spalling

So, here's my reasoning behind asking @jfhc to create this request:

Shebang lines are special. They can be unfortunately long - I usually only see this with auto-generated lines but it's not outside the realm of possibility that it could be hand-crafted as well. Normally, my answer would be to just tack # noqa onto the end, but in this case, that would break the shebang. There's no good way of handling this without changing the style of the entire file/project. To ignore shebangs is incredibly easy (if first line and starts with #! skip line length check)

In my case the shebangs are long because of the way my workplace manages python environments (so my shebang line essentially points to a wrapper script with some extra arguments which grabs the right python for the script).

@jfhc Oh neat! I didn't know you could do that.

Got my vote then.

@jfhc I'd happily merge a PR that adds this feature. Would you be interested in contributing it?

I'd be up for giving it a go :-) @sigmavirus24

Please do @jfhc 馃槂

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZeeD26 picture ZeeD26  路  5Comments

lzkelley picture lzkelley  路  7Comments

joshbode picture joshbode  路  4Comments

gvanrossum picture gvanrossum  路  7Comments

Nyrio picture Nyrio  路  4Comments