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

Add keyword-argument to no-space-check option #1368

Closed
eight04 opened this issue Mar 10, 2017 · 6 comments
Closed

Add keyword-argument to no-space-check option #1368

eight04 opened this issue Mar 10, 2017 · 6 comments
Labels
Enhancement ✨ Improvement to a component Proposal 📨

Comments

@eight04
Copy link

eight04 commented Mar 10, 2017

This is a feature request.

Currently "no-space-check" option accepts "dict-separator" to allow spaces beside ":"

# valid
{
	"a": "...",
	"bb": "...",
	"ccc": "..."
}
# valid with no-space-check=dict-separator
{
	"a":   "...",
	"bb":  "...",
	"ccc": "..."
}
{
	"a"  : "...",
	"bb" : "...",
	"ccc": "..."
}

How about to allow spaces for keyword arguments?

# valid
dict(
	a="...",
	bb="...",
	ccc="..."
)
# valid with no-space-check=keyword-argument
dict(
	a = "...",
	bb = "...",
	ccc = "..."
)
dict(
	a =   "...",
	bb =  "...",
	ccc = "..."
)
dict(
	a   = "...",
	bb  = "...",
	ccc = "..."
)

Then the user won't need to disable entire "bad-whitespace" if they want to allow spaces between "=" for keyword arguments.

pylint --version output

No config file found, using default configuration
pylint 1.7.0,
astroid 1.5.0
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (In
tel)]
@rogalski rogalski added Enhancement ✨ Improvement to a component Proposal 📨 labels Mar 10, 2017
@Thf772
Copy link

Thf772 commented Jun 14, 2019

Its implementation should be easily done by adding a condition there:
https://github.com/PyCQA/pylint/blob/3dd27c907b1230f889d0c010de51a99e9291a60f/pylint/checkers/format.py#L866

# UNTESTED
if _KEYWORD_ARGUMENT in self.config.no_space_check:
    self._check_space(tokens, i, (_IGNORE, _IGNORE))
else:
    self._check_space(tokens, i, (_MUST_NOT, _MUST_NOT))

I might make a fork-and-pull-request myself if I find the time to do it properly.

@Pierre-Sassoulas
Copy link
Member

bad-whitespace has been removed in #3572 , along with the no-space-check option. black or another formatter can help you with this better than Pylint.

@bertsky
Copy link

bertsky commented Sep 14, 2020

bad-whitespace has been removed in #3572 , along with the no-space-check option. black or another formatter can help you with this better than Pylint.

I can only find mention of bad-whitespace, not no-space-check in that PR and its linked issue discussion. Why did you just remove that useful feature? PEP 8 used to say that block indentation should be kept for empty lines. I know it does not (anymore), but many editors still do, and the Python interpreter still needs the indentation (e.g. when pasting code verbatim).

Now I have to run my source files with trailing-whitespace disabled, which covers up all the actual trailing whitespace.

@Pierre-Sassoulas
Copy link
Member

Hello, @bertsky ,

The PR linked in the issue show the actual removal of the no-space-check option https://github.com/PyCQA/pylint/pull/3577/files#diff-89a2fba770c65703addbc42a471241e0L340 as well as the discussion of why we removed it in the issue linked.

To sumup, we removed bad-whitespace mainly because it had a huge maintenance cost and because tons of tool handle this well (black in particular).

For your actual problem, if you really want to copy-paste into the interpreter while keeping that old pep8 rule; I would advise to remove the empty lines, keep the old version of pylint, or create a fork.

@bertsky
Copy link

bertsky commented Sep 14, 2020

Hi @Pierre-Sassoulas,
thanks for elaborating!

Sorry, I missed that second related PR.

IIUC you advise to use code formatters to preprocess the source (before pylint gets to see it) – right? (Or is it the other way round – you expect source files to adhere to your conventions strictly, and advise code formatters to generate representations for the human eye?)

For your actual problem, if you really want to copy-paste into the interpreter while keeping [sic; I think you actually meant abandoning] that old pep8 rule; I would advise to remove the empty lines, keep the old version of pylint, or create a fork.

I usually use pylint as part of CI, so neither holding pylint at the old version nor forking appear very attractive.

Pasting into the interpreter is a rather casual use-case for me (I just brought it up for completeness). My sources are mostly following that old convention, and my editor uses it. So you recommend reformatting sources (e.g. with black) and sticking with the new convention for good?

@Pierre-Sassoulas
Copy link
Member

Yes, I strongly advise to not bother with manual formatting at all and let black, isort, and pre-commit, unimport and probably others do the hard boring work automatically before using pylint. It permits to remove all formatting checks from pylint and other checkers like flake8. Those check won't fail after that, or should not fail.

Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.
https://github.com/psf/black

See also http://pylint.pycqa.org/en/latest/faq.html#i-am-using-another-popular-linter-alongside-pylint-which-messages-should-i-disable-to-avoid-duplicates for pylint configuration for cohabitation with other checkers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Proposal 📨
Projects
None yet
Development

No branches or pull requests

5 participants