-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BOM-1074 - Run black on edx-lint #108
Conversation
047beb0
to
e752aee
Compare
Seems like black doesn't know our line length is 120? |
e752aee
to
6381a38
Compare
@nedbat yea, I had left it alone until I figured out if I wanted at pyproject.toml or not. But added it to the make targets for now. |
This does the minimum amount neede to no longer test on python 2.7
When we run pylint in python 3.5 we get new errors and a bunch of previous disables are no longer necessary. This cleans up all of those issues.
6381a38
to
743e53e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mind me, just griping. The code used to be nice... :(
edx_lint/cmd/amnesty.py
Outdated
@@ -21,7 +21,8 @@ | |||
) | |||
PYLINT_EXCEPTION_REGEX = re.compile(r"""\s*#\s*pylint:\s+disable=(?P<disables>[^#$]+?)(?=\s*(#|$))""") | |||
|
|||
PylintError = namedtuple('PylintError', ['filename', 'linenum', 'error_code', 'error_name', 'function', 'error_msg']) | |||
PylintError = namedtuple("PylintError", ["filename", "linenum", "error_code", "error_name", "function", "error_msg"],) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a logic to why there's a trailing comma now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this started with the latest black release (19.10b0), the previous 19.3b0 doesn't do this. Seems to be an unintended side-effect of psf/black#826 , may be worth filing a bug for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we revert the new trailing commas before merging this? Re-running Black with version 19.3b0 should fix it, not sure if that would make any other undesired changes.
@@ -27,5 +28,5 @@ def usable_class_name(node): | |||
name = node.qname() | |||
for prefix in ["__builtin__.", "builtins.", "."]: | |||
if name.startswith(prefix): | |||
name = name[len(prefix):] | |||
name = name[len(prefix) :] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably no point asking why black inserted a space before the colon....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Details in psf/black#279 . Comes from the following part of PEP 8:
However, in a slice the colon acts like a binary operator, and should have equal amounts on either side (treating it as the operator with the lowest priority). In an extended slice, both colons must have the same amount of spacing applied. Exception: when a slice parameter is omitted, the space is omitted.
PEP 8 basically allows for either sequence[a:b]
or sequence[a : b]
, but not sequence[a: b]
. The second of those condenses to the above when the second parameter is missing. Granted, the code before the change is perfectly PEP 8 compliant also, I think they just didn't want to try to figure out under which conditions the space after a colon is ok to omit.
edx_lint/cmd/amnesty.py
Outdated
@@ -21,7 +21,8 @@ | |||
) | |||
PYLINT_EXCEPTION_REGEX = re.compile(r"""\s*#\s*pylint:\s+disable=(?P<disables>[^#$]+?)(?=\s*(#|$))""") | |||
|
|||
PylintError = namedtuple('PylintError', ['filename', 'linenum', 'error_code', 'error_name', 'function', 'error_msg']) | |||
PylintError = namedtuple("PylintError", ["filename", "linenum", "error_code", "error_name", "function", "error_msg"],) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this started with the latest black release (19.10b0), the previous 19.3b0 doesn't do this. Seems to be an unintended side-effect of psf/black#826 , may be worth filing a bug for.
edx_lint/cmd/amnesty.py
Outdated
disabled=", ".join(sorted(error_names)), | ||
tag=tag_str, | ||
) | ||
return u" # {tag}pylint: disable={disabled}".format(disabled=", ".join(sorted(error_names)), tag=tag_str,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trailing comma here is also omitted under black 19.3b0.
.travis.yml
Outdated
env: TOXARG="-e pylint" | ||
- python: "3.6" | ||
env: TOXARG="-e black-test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
black not working under Python 3.5 is going to be annoying given that we'll probably be running 3.5 as our default dev environment in most repos for another few months.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I think it may point to us waiting to actually deploy this until we're on 3.6 and above. Especially since python 3.6 won't be available on devstack by default. I think this was a good learning experience but we may want to hold off on actually turning on black for everything until we're on a newer version of python. @nedbat @jmbowman thoughts?
@@ -27,5 +28,5 @@ def usable_class_name(node): | |||
name = node.qname() | |||
for prefix in ["__builtin__.", "builtins.", "."]: | |||
if name.startswith(prefix): | |||
name = name[len(prefix):] | |||
name = name[len(prefix) :] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Details in psf/black#279 . Comes from the following part of PEP 8:
However, in a slice the colon acts like a binary operator, and should have equal amounts on either side (treating it as the operator with the lowest priority). In an extended slice, both colons must have the same amount of spacing applied. Exception: when a slice parameter is omitted, the space is omitted.
PEP 8 basically allows for either sequence[a:b]
or sequence[a : b]
, but not sequence[a: b]
. The second of those condenses to the above when the second parameter is missing. Granted, the code before the change is perfectly PEP 8 compliant also, I think they just didn't want to try to figure out under which conditions the space after a colon is ok to omit.
@@ -2,3 +2,4 @@ | |||
|
|||
tox | |||
tox-battery | |||
black |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since black doesn't work under Python 3.5, this will force dev environments to use Python 3.6+ . That's a little less than ideal if we want to keep running make upgrade
under 3.5 since that's our primary target version for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with postponing black indefinitely :) |
tox.ini
Outdated
pylint --version | ||
coverage run -p -m pytest {posargs:} | ||
|
||
[testenv:coverage] | ||
envdir = {toxworkdir}/py27-pylint17 | ||
envdir = {toxworkdir}/py35-pylint17 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this and testenv:pylint
below be updated to use pylint24 instead?
edx_lint/cmd/amnesty.py
Outdated
@@ -21,7 +21,8 @@ | |||
) | |||
PYLINT_EXCEPTION_REGEX = re.compile(r"""\s*#\s*pylint:\s+disable=(?P<disables>[^#$]+?)(?=\s*(#|$))""") | |||
|
|||
PylintError = namedtuple('PylintError', ['filename', 'linenum', 'error_code', 'error_name', 'function', 'error_msg']) | |||
PylintError = namedtuple("PylintError", ["filename", "linenum", "error_code", "error_name", "function", "error_msg"],) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we revert the new trailing commas before merging this? Re-running Black with version 19.3b0 should fix it, not sure if that would make any other undesired changes.
We still have a lot of repos that are going to be running on 3.5, it would be really annoying for them if they needed a second venv just to run black. Especially because it might not always be possible in various dev/test environments. We'll just hold off on enforcing this till next year when we're on at least 3.6
Since we're dropping support for python 2.7 we can also drop support for the old version of pylint and pylint-django.
24c5aca
to
cc96245
Compare
No description provided.