-1

The project I'm working on runs a linting check before validating the build. The linter checks PEP8 compliance among other things. I have a base64 string, that's about 5,000 characters long (it's a file converted into a base64 string), and so of course, the linter doesn't like it.

It seems to me like it would be really dumb to just split the string into 60+ lines just to make it PEP8 compliant.

Having the file as a physical file and reading it on the fly isn't really an option for the context. Reading a file from an external source isn't an option either.

Edit: The PEP8 compliance check is done with Flake8

Looking for suggestions on how to go about this.

Verv
  • 2,385
  • 2
  • 23
  • 37
  • 3
    "It seems to me like it would be really dumb to just split the string into 60+ lines just to make it PEP8 compliant." — Why? If you want to be PEP 8 compliant, and putting the string outside the source code isn't an option, splitting the string up is pretty much your only option. – jwodder Aug 02 '17 at 15:18
  • Agreed with @jwodder, assuming this is a string that won't be changing often (which I assume is the case since the string is not in an external file). Splitting the string into lines should take no more than 30 seconds with a decent editor. – 0x5453 Aug 02 '17 at 15:20
  • 1
    @Verv I suppose there is also an argument for adding `# nopep8`/`# noqa` at the end of the line if your linter supports it. – 0x5453 Aug 02 '17 at 15:26
  • @0x5453 exactly the kind of alternative I was looking for, I'll look into this and see if it is indeed supported, thanks. – Verv Aug 02 '17 at 15:27
  • @Verv Could you use a triple-quote string literal to avoid splitting the lines? Would the linter complain about the length even in this case? – George Pantazes Aug 02 '17 at 15:33

1 Answers1

2

A foolish consistency is the hobgoblin of little minds

PEP8 is a style guide, not a rulebook. There are instances where it is best to ignore PEP8. Don't sacrifice code clarity for the sake of compliance. Is avoiding a single linter warning better than forcing your code into 60 lines and dealing with all the line breaks?

It seems to me like it would be really dumb to just split the string into 60+ lines just to make it PEP8 compliant.

It is.

Depending on your linter, you may be able to put # noqa at the end of the offending line in order for it to ignore the PEP8 non-compliance. Check your linter documentation to see what it offers in this regard.

Tetra
  • 153
  • 10