-
Notifications
You must be signed in to change notification settings - Fork 278
chore: check ruff C4 #962
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
chore: check ruff C4 #962
Conversation
|
I don't really agree with this one, at least when it comes with dictionaries, when you're passing dictionaries to be used as arguments I much prefer the Not only does it read closer to the keyword parameters your passing it forces the keword names to be valid. |
|
For general use, I strongly prefer the literal over a dict call; literals are native syntax, about 30% faster, and support arbitrary keys; they are the only candidate for the "one obvious way to do it". However, I see the >>> def f(**kwargs):
... print(kwargs)
...
>>> f(**{"class": 1})
{'class': 1}
>>> f(**{"1": 1})
{'1': 1}That is, Python itself doesn't enforce valid keyword names. :) IMO, since there are just two cases of this, with just one argument: - assert Marker('"2.7.9" < "foo"').evaluate(dict(foo="2.7.10"))
+ assert Marker('"2.7.9" < "foo"').evaluate({"foo": "2.7.10"})I think adding the check with the changes is fine, but I'd also be fine to skip those two, or even disable the check on the tests folder (but still apply the |
Ah, I should have made clear, I agree in general that literal syntax is preferable. But I don't agree in all cases, and to me all three examples here are more readable as dict calls.
I believe the actual text in the Zen is intended to be ironic, the em-dashes are inconsistently spaced. And the rule here, C408, has a specific options just for this case: allow-dict-calls-with-keyword-arguments, so it seems I'm not the only one who feels this way. |
8607681 to
54cff86
Compare
|
New version, ignoring this rule in tests, but still applying it to the one clear dict case. Is that better? (I can't apply a rule like disabling it for dict on only |
54cff86 to
e5a48c5
Compare
|
I would strongly prefer setting allowing dict calls with keyword arguments as opposed to excluding C408 arbitrarily on tests, and leave the correct syntax up to authors and reviewers, i.e. [tool.ruff.lint.flake8-comprehensions]
allow-dict-calls-with-keyword-arguments = trueAlso, to a much lesser extent, I don't prefer the transformation of the dict. But I am not going to block this PR over my personal preference. |
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
fd3824f to
c2d22f4
Compare
|
I'm happy to go with that if you feel strongly enough. I don't think the core library (for something like packaging) should have any dict(kw)'s, but fine to disable it. Tests don't matter, but I can't change a setting per directory. |
Comprehensions.