Skip to content
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

Merged
merged 11 commits into from
Dec 9, 2019
Merged

BOM-1074 - Run black on edx-lint #108

merged 11 commits into from
Dec 9, 2019

Conversation

feanil
Copy link
Contributor

@feanil feanil commented Dec 2, 2019

No description provided.

@feanil feanil force-pushed the feanil/black-it branch 3 times, most recently from 047beb0 to e752aee Compare December 2, 2019 19:42
@nedbat
Copy link
Contributor

nedbat commented Dec 2, 2019

Seems like black doesn't know our line length is 120?

@feanil
Copy link
Contributor Author

feanil commented Dec 2, 2019

@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.

@feanil feanil requested a review from jmbowman December 2, 2019 20:27
@feanil feanil changed the title Feanil/black it BOM-1074 - Run black on edx-lint Dec 2, 2019
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.
Copy link
Contributor

@nedbat nedbat left a 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... :(

@@ -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"],)
Copy link
Contributor

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?

Copy link

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.

Copy link

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) :]
Copy link
Contributor

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

Copy link

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/pylint/i18n_check.py Outdated Show resolved Hide resolved
edx_lint/pylint/i18n_check.py Outdated Show resolved Hide resolved
test/plugins/test_range_check.py Outdated Show resolved Hide resolved
test/plugins/test_right_assert_check.py Outdated Show resolved Hide resolved
@@ -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"],)
Copy link

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.

disabled=", ".join(sorted(error_names)),
tag=tag_str,
)
return u" # {tag}pylint: disable={disabled}".format(disabled=", ".join(sorted(error_names)), tag=tag_str,)
Copy link

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"
Copy link

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.

Copy link
Contributor Author

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) :]
Copy link

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
Copy link

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.

tox.ini Outdated Show resolved Hide resolved
Copy link
Contributor Author

@feanil feanil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 3.6 min requirement is unfortunate and I'm leaning towards waiting till our dev envs meet it before we push this forward, what do you think @nedbat @jmbowman ?

@nedbat
Copy link
Contributor

nedbat commented Dec 3, 2019

I am fine with postponing black indefinitely :)

@feanil feanil requested a review from jmbowman December 4, 2019 21:58
tox.ini Outdated
pylint --version
coverage run -p -m pytest {posargs:}

[testenv:coverage]
envdir = {toxworkdir}/py27-pylint17
envdir = {toxworkdir}/py35-pylint17
Copy link

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?

@@ -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"],)
Copy link

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.

@feanil feanil requested a review from jmbowman December 6, 2019 19:53
feanil and others added 7 commits December 9, 2019 11:14
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.
@feanil feanil merged commit 17c3bd0 into master Dec 9, 2019
@feanil feanil deleted the feanil/black-it branch December 9, 2019 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants