Repository navigation
Address Ruff Rule C408 in astropy/io Sub-package - #14841
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
Thanks @Mubin17! This all looks very good. And it's wise to tackle these corrections on a sub package basis. Line 32 in 12b01d7 and copy it to the per-file-ignore list (at Lines 287 to 309 in 12b01d7 astropy/io of course, that would be great! Also, fixing C408 in the next sub package is as easy as removing it from the relevant per-file-ignore list!
|
taldcroft
left a comment
There was a problem hiding this comment.
Looks fine from the io.ascii perspective.
|
Modifications to |
pllim
left a comment
There was a problem hiding this comment.
Please do not introduce merge commit in your PR commits. You need to rebase instead. Thanks!
|
@pllim Sorry about that but I am lost kind of lost on what am I supposed to do next. I don’t have much experience with rebase, something goes wrong whenever I try it, so it would be great if you perform the rebase you can or guide me on how can I rebase. Thanks |
|
@Mubin17 , please try the following:
When you are confident it is correctly done, do Good luck! |
1fb9e71 to
f4effc3
Compare
|
@pllim Thanks for the help! |
|
I notice this pull request has two commits: the first fixes the rule violations in |
Thanks @eerovaher for the suggestion! I feel like editing the .ruff.toml file first and then committing the changes without manual file editing sounds like a much smoother workflow. I'll definitely keep this in mind when I tackle Ruff rule-C408 in other Astropy sub-packages. Just a quick question: Do you think the current pull request is ready to be merged, or if there are any additional changes or considerations you would like me to address? Thanks again! |
|
I suggest squashing the commits. I have an additional recommendation about commit messages. GitHub knows which commits belong to which pull requests regardless of the commit messages, and linking pull requests to issues does not depend on the commit messages either. Including GitHub issues in commit messages therefore provides little benefit to GitHub users. Furthermore, issues and pull requests are a GitHub feature, not a Git feature, so including issue numbers in commit messages usually doesn't help anyone using Git either, although there are some exceptions to this. Replacing |
f4effc3 to
081c892
Compare
|
@eerovaher I've squashed all the commits into one and have updated the commit messages to an appropriate one. |
There was a problem hiding this comment.
Thanks @Mubin17. This all looks very straightforward and it's nice there's an autofix available.
As reference for anyone looking at this: Rule C408 has 2 benefits:
- it's faster because there's no global namespace lookup.
- it's safer because callables like
dictcan be rebound, but language-level syntax like{}cannot, so{}unambiguously means a dict has been created.
eerovaher
left a comment
There was a problem hiding this comment.
Currently C408 is being removed from the global ignore list and is added to the ignore lists of individual sub-packages, except for astropy/io in which the violations are fixed. However, there are subpackages in astropy that already comply with C408. I have highlighted astropy/config, but there are more. C408 should only be added to the ignore lists of the sub-packages where it is needed.
| "astropy/coordinates/*" = ["I001"] | ||
| "astropy/cosmology/*" = [] | ||
| "astropy/__init__.py" = ["C408"] | ||
| "astropy/config/*" = ["C408"] |
There was a problem hiding this comment.
astropy/config already complies with C408, so Ruff shouldn't be told to ignore this rule there.
8c284af to
7c83005
Compare
|
@eerovaher I have made the requested changes, can you please review them? Let me know if anything else needs changes. Thanks |
|
@nstarman Does this PR need any additional changes? If not can it be merged? |
|
I think we’re good to go. IMO this is a clear and positive change. Thanks @Mubin17 for the PR! |
Description
Refactored the code in the astropy/io sub-package to address the Ruff rule C408 violation. Replaced unnecessary dict calls with corresponding literals.
This pull request is to address Issue #14840
Fixes #14840