-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enforce ruff/flake8-implicit-str-concat rules (ISC) #4411
Conversation
1f218d4
to
7309fbf
Compare
@@ -257,7 +257,7 @@ def test_marker_evaluation_with_extras(self): | |||
"/foo_dir/Foo-1.2.dist-info", | |||
metadata=Metadata(( | |||
"METADATA", | |||
"Provides-Extra: baz\n" "Requires-Dist: quux; extra=='baz'", | |||
"Provides-Extra: baz\nRequires-Dist: quux; extra=='baz'", |
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.
Use triple-quoted strings instead?
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 don't think it is necessary to use triple-quotes here, specially in the context of quick tests...
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.
But then tests are as important and should be as maintainable as the source code.
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 don't think that adding an explicit \n
makes short snippets unreadable.
For tests, it even makes sense, because we are explicitly saying there should be a \n
there...
On the other hand, using triple quotes for short strings either results in distracting code (e.g. when the indentation is broken inside the triple-quotes), or requires you to bring out the big guns (e.g. inspect.cleandoc
).
'getsourcefile', | ||
'getfile' 'getsourcelines', | ||
'getsourcelines', |
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.
That was a real bug!
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.
Thank you very much @DimitriPapadopoulos for working on this.
Given that this PR for the time being is failing the CI, would you like to extract the bug fixes in a PR of their own?
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 can do that, but what's the intent? As far as I can tell, this change is not (directly) responsible for the CI failures.
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.
Great, if the CI is no longer failure that is OK. We can proceed with this PR.
@@ -83,7 +83,7 @@ def test_read_attr(self, tmp_path, monkeypatch): | |||
"pkg/__init__.py": "", | |||
"pkg/sub/__init__.py": "VERSION = '0.1.1'", | |||
"pkg/sub/mod.py": ( | |||
"VALUES = {'a': 0, 'b': {42}, 'c': (0, 1, 1)}\n" "raise SystemExit(1)" | |||
"VALUES = {'a': 0, 'b': {42}, 'c': (0, 1, 1)}\nraise SystemExit(1)" |
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.
Use triple-quoted strings instead?
@@ -35,7 +35,7 @@ def fake_env( | |||
tmpdir, setup_cfg, setup_py=None, encoding='ascii', package_path='fake_package' | |||
): | |||
if setup_py is None: | |||
setup_py = 'from setuptools import setup\n' 'setup()\n' | |||
setup_py = 'from setuptools import setup\nsetup()\n' |
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.
Use triple-quoted strings instead?
@@ -97,7 +97,7 @@ def test_no_config(self, tmpdir): | |||
def test_ignore_errors(self, tmpdir): | |||
_, config = fake_env( | |||
tmpdir, | |||
'[metadata]\n' 'version = attr: none.VERSION\n' 'keywords = one, two\n', | |||
'[metadata]\nversion = attr: none.VERSION\nkeywords = one, two\n', |
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.
Use triple-quoted strings instead?
@@ -171,22 +171,22 @@ def test_license_cfg(self, tmpdir): | |||
def test_file_mixed(self, tmpdir): | |||
fake_env( | |||
tmpdir, | |||
'[metadata]\n' 'long_description = file: README.rst, CHANGES.rst\n' '\n', | |||
'[metadata]\nlong_description = file: README.rst, CHANGES.rst\n\n', |
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.
Use triple-quoted strings instead?
) | ||
|
||
tmpdir.join('README.rst').write('readme contents\nline2') | ||
tmpdir.join('CHANGES.rst').write('changelog contents\nand stuff') | ||
|
||
with get_dist(tmpdir) as dist: | ||
assert dist.metadata.long_description == ( | ||
'readme contents\nline2\n' 'changelog contents\nand stuff' | ||
'readme contents\nline2\nchangelog contents\nand stuff' |
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.
Use triple-quoted strings instead?
) | ||
|
||
def test_file_sandboxed(self, tmpdir): | ||
tmpdir.ensure("README") | ||
project = tmpdir.join('depth1', 'depth2') | ||
project.ensure(dir=True) | ||
fake_env(project, '[metadata]\n' 'long_description = file: ../../README\n') | ||
fake_env(project, '[metadata]\nlong_description = file: ../../README\n') |
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.
Use triple-quoted strings instead?
@@ -253,7 +253,7 @@ def test_dict(self, tmpdir): | |||
|
|||
def test_version(self, tmpdir): | |||
package_dir, config = fake_env( | |||
tmpdir, '[metadata]\n' 'version = attr: fake_package.VERSION\n' | |||
tmpdir, '[metadata]\nversion = attr: fake_package.VERSION\n' |
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.
Use triple-quoted strings instead?
@@ -180,7 +180,8 @@ class TestFlatLayoutPackageFinder: | |||
[ | |||
"pkg/__init__.py", | |||
"examples/__init__.py", | |||
"examples/file.py" "example/other_file.py", | |||
"examples/file.py", | |||
"example/other_file.py", |
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.
Again a real bug!
ISC001 definitively as there's no valid reason to ISC on a single line. It just makes the line longer and is likely to accidentally create bugs (which you did catch!) ISC002 vs ISC003 is more opinionated, so up to the maintainers. Personally I prefer disallowing multiline implicit string concatenation as it helps from a quick read understanding that two lines are not two parameters. Also here's a feature request to control |
About
I think it make sense to unfold user-visible strings, I seem to recall ruff does allow literal strings longer than the admissible line length, up to a larger limit at least. |
ISC001 Implicitly concatenated string literals on one line Only fix actual bugs in this PR, at least until unrelated CI failures are fixed.
I've changed this PR to only fix actual bugs uncovered by |
We should probably align with skeleton. |
Thank you very much @DimitriPapadopoulos. |
It clearly a bad idea to ignore |
My bad, I am actually the one who (temporarily) ignored In the meantime, I think it makes sense to apply |
Summary of changes
ISC001 Implicitly concatenated string literals on one line
ISC003 Explicitly concatenated string should be implicitly concatenated
Pull Request Checklist
newsfragments/
.(See documentation for details)