Skip to content

Comments

Remove "indx" from codespell ignore list#17725

Merged
neutrinoceros merged 1 commit intoastropy:mainfrom
eerovaher:codespell-2-4-1
Feb 8, 2025
Merged

Remove "indx" from codespell ignore list#17725
neutrinoceros merged 1 commit intoastropy:mainfrom
eerovaher:codespell-2-4-1

Conversation

@eerovaher
Copy link
Member

@eerovaher eerovaher commented Feb 4, 2025

Description

The upgraded codespell doesn't like the variable name indx. In #17720 those variables are renamed to index, but indx is quite a common name, so the question was raised in that pull request if the code churn is worth it. In many places it is simple enough to rewrite the code so that the indx/index variable is not needed at all. I thought that if we are editing the code because codespell anyways then we might as well edit it properly, so I am opening this as an alternative for #17720.

EDIT: Close #17720

I also found a line of code in io.fits that I suspect has a bug in it. It is possible the labels might have to change the labels if maintainer confirms. See the inline comment for details.

UPDATE

#17720 has been merged, so now this pull request only removes "indx" from the codespell ignore list.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2025

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.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

indx.remove(x)
tmp = [self[i] for i in indx]
return ColDefs(tmp)
return ColDefs([self[i] for i in range(len(self)) if i not in _other])
Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I can tell ColDefs is not an iterable, so it is not possible to use enumerate(self) here.

Copy link
Contributor

Choose a reason for hiding this comment

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

A quick trial seems to suggest ducktyping is in good form for enumerating: just having __getitem__ seems to be enough:

class A:
   def __getitem__(self, i):
        if i < 4:
            return "abc"[i]
        raise IndexError
 
for i, a in enumerate(A()): print(i, a)
0 a
1 b
2 c

Copy link
Member Author

Choose a reason for hiding this comment

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

The code here is not covered by tests, so I don't feel very comfortable editing it more than I already have.

@neutrinoceros
Copy link
Contributor

I agree this is generally better than my own #17720, which I can close now.
It'd be best to get some feedback from io.fits maintainers before we merge, though as far as I can tell this is a clear bug-for-bug refactor so far.

Copy link
Member

@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

Thanks @eerovaher.
Approving, pending approval for changes to fits stuff.

@pllim
Copy link
Member

pllim commented Feb 6, 2025

I just merged #17720 so this might need rebase. I apologize for any inconvenience caused.

@eerovaher eerovaher changed the title Upgrade codespell to 2.4.1 Remove "indx" from codespell ignore list Feb 6, 2025
Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Agreed that this is nicer! One comment, but fine to merge without addressing that.

indx.remove(x)
tmp = [self[i] for i in indx]
return ColDefs(tmp)
return ColDefs([self[i] for i in range(len(self)) if i not in _other])
Copy link
Contributor

Choose a reason for hiding this comment

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

A quick trial seems to suggest ducktyping is in good form for enumerating: just having __getitem__ seems to be enough:

class A:
   def __getitem__(self, i):
        if i < 4:
            return "abc"[i]
        raise IndexError
 
for i, a in enumerate(A()): print(i, a)
0 a
1 b
2 c


# if more than one group parameter have the same name, the
# value must be a list (or tuple) containing arrays
elif not isinstance(value, (list, tuple)) or len(index) != len(value):
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I'd switch the order, i.e., keep the original if but just make it an elif (no not, or->and) and write an else that raises at the end.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to rebase anyways to solve a merge conflict.

In many places variables named `indx` were renamed to `index`, but in a
few places it was possible to rewrite the code to avoid the variables
entirely.
@mhvk
Copy link
Contributor

mhvk commented Feb 7, 2025

Yes, fine to leave the iteration alone! Feel free to merge.

@neutrinoceros
Copy link
Contributor

3 approvals, and the branch already required 2 rebases in as many days. I'll just push the button now. Thanks !

@neutrinoceros neutrinoceros merged commit 11aa662 into astropy:main Feb 8, 2025
27 checks passed
mhvk pushed a commit to mhvk/astropy that referenced this pull request Feb 9, 2025
@eerovaher eerovaher deleted the codespell-2-4-1 branch February 10, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants