How would I handle long path name like below for pep8 compliance? Is 79 characters per line a must even if it becomes somewhat unreadable?
def setUp(self):
self.patcher1 = patch('projectname.common.credential.CredentialCache.mymethodname')
There are multiple ways to do this:
Use a variable to store this
def setUp(self):
path = 'projectname.common.credential.CredentialCache.mymethodname'
self.patcher1 = patch(path)
String concatenation:
An assignment like v = ("a" "b" "c")
gets converted into v = "abc"
:
def setUp(self):
self.patcher1 = patch(
"projectname.common.credential."
"CredentialCache.mymethodname")
Tell pep8 that we don't use 80-column terminals anymore with --max-line-length=100 (or some sufficiently reasonable value). (Hat Tip @chepner below :) )
The 79-character limit in PEP8 is based more on historical beliefs than in actual readability. All of PEP8 is a guideline, but this one is more frequently ignored than most of the recommendation. The pep8
tool even has a specific option for changing the value of what is considered "too long".
pep8 --max-line-length 100 myscript.py
I frequently just disable the test altogether:
pep8 --ignore E501 myscript.py
I prefer variant with concatenation.
def setUp(self):
self.patcher1 = patch(
"projectname.common.credential."
"CredentialCache.mymethodname")
Also concatenation braces are not required when calling a function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With