Skip to content

Change the quotes in the repr of units from " to ' - #18509

Draft
eerovaher wants to merge 1 commit into
astropy:mainfrom
eerovaher:unit-repr-quotes
Draft

eerovaher wants to merge 1 commit into
astropy:mainfrom
eerovaher:unit-repr-quotes

Conversation

@eerovaher

Copy link
Copy Markdown
Member

Description

The repr of Python strings uses ', not ", so to be consistent with that the repr of astropy units should also use '. The reason why " is currently used is a change in bd684a0. From what I can tell the change was arbitrary and I couldn't find any discussion about it.

There is no change in the repr of Quantity and in any case APE 2 allows changing the output of __repr__() even in bugfix releases.

  • 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
Copy Markdown
Contributor

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.

Comment on lines 105 to +108
>>> su.field_names
(['f0', ('f0', 'f1')], 'f1')
>>> su['f1']
Unit("yr")
Unit('yr')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Notice that the quotes are now consistent with the quotes in field_names.

Comment thread astropy/units/tests/test_units.py Outdated
Comment on lines +734 to +735
"^Object with NFKC normalized name 'h' already exists in given namespace "
r'\(Unit\("h"\)\)\.$'
r"\(Unit\('h'\)\)\.$"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If this error message is ever shortened so that it would fit on one line then without this patch it would be necessary to explicitly escape the quotation marks within the string.


>>> sc_gal.representation_component_units
{'l': Unit("deg"), 'b': Unit("deg")}
{'l': Unit('deg'), 'b': Unit('deg')}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No good reason for using both ' and " here.

The repr of Python strings uses `'`, not `"`, so for consistency the
repr of `astropy` units should also use `'`. This change does not affect
the representation of `Quantity` instances.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, I think that original change is indeed a mistake, so from that perspective good to correct it. It is also is just that little bit cleaner repr, making it easier to parse (though inconsistent with ruff -- IMO, it would've been better if ruff preferred single quotes too).

It is more than a little churn, though, likely to break at least some doctests downstream as well, so I'd like agreement from the other reviewers that this is worth it.

Thankfully, in most cases (Quantity, Table, SkyCoord, etc.), the repr is not used; the corrections here are almost all just places where the docs explicitly look at a unit.

Overall, +0.5 myself.

@eerovaher

Copy link
Copy Markdown
Member Author

Nobody has objected, so we can move forward with this.

It is also is just that little bit cleaner repr, making it easier to parse (though inconsistent with ruff -- IMO, it would've been better if ruff preferred single quotes too).

I don't understand what you mean by that.

@mhvk

mhvk commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

It is also is just that little bit cleaner repr, making it easier to parse (though inconsistent with ruff -- IMO, it would've been better if ruff preferred single quotes too).

I don't understand what you mean by that.

Just grumpy me that ruff chose to use the quote for strings that is not the default in python repr. Nothing one can do about it for this PR, though.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, happy to sign off on this for the units part.

Would like sign off for the other packages, though, so ping again @modelling, @cosmology, @taldcroft, @mwcraig, @bmorris3.

@github-project-automation github-project-automation Bot moved this from Triage to Reviewer approved in Cosmology, the Expansion Aug 25, 2025
@taldcroft

Copy link
Copy Markdown
Member

I would suggest to bump this up to an email to astropy-dev for consideration. This is a pretty good example of a PR that makes no functional improvement to astropy but has the potential to cause non-productive work downstream.

@taldcroft

Copy link
Copy Markdown
Member

So please DO NOT merge just yet.

@taldcroft

Copy link
Copy Markdown
Member

And my feedback is that we've lived this for 11 years and given the ruff precedent and significant potential for needless docstring breakage downstream, I'm 👎 on this PR.

@nstarman nstarman left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cosmology and units LGTM.
It is a move towards the PEP8 standards and general consistency with most other libraries.
While APE 2 does allow for __repr__ changes I do agree that Quantity and Unit are some of the most likely to show up in downstream doctests, so for that reason we should.

  1. Do this for a Major.0 release.
  2. Add to the what'snew a link to pytest-doctestplus's instructions on how to restrict doctests to specific versions of Astropy.

@github-actions

github-actions Bot commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@github-actions github-actions Bot added the closed-by-bot Closed by stale bot label Feb 8, 2026
@github-actions

github-actions Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks!

If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here.

@github-actions github-actions Bot closed this Feb 8, 2026
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in Cosmology, the Expansion Feb 8, 2026
@nstarman nstarman reopened this Feb 9, 2026
@github-project-automation github-project-automation Bot moved this from Done to In Progress in Cosmology, the Expansion Feb 9, 2026
@nstarman nstarman removed Close? Tell stale bot that this issue/PR is stale closed-by-bot Closed by stale bot labels Feb 9, 2026
@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Feb 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 6 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@nstarman nstarman added keep-open and removed Close? Tell stale bot that this issue/PR is stale labels Feb 11, 2026
@astrofrog astrofrog modified the milestones: v8.0.0, v8.1.0 May 5, 2026
@pllim pllim removed the keep-open label Oct 14, 2026
@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 1 year, 2 months. I plan to close this in a month if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@nstarman

nstarman commented Nov 8, 2026

Copy link
Copy Markdown
Member

This was deferred to v8. That milestone has passed. @mhvk should we merge this?

@pllim

pllim commented Nov 9, 2026

Copy link
Copy Markdown
Member

You cannot merge in this state. It has conflicts and failing CI. Someone has to take over if Eero is unresponsive.

@mhvk

mhvk commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@nstarman - I'm still the same +0.5, and happy to get this in, but someone would need to clean it up and check against coordinated packages to have a sense of how much or little breakage this causes. Unfortunately, I don't see myself having time...

@taldcroft

Copy link
Copy Markdown
Member

Making this change so close to the end of the release cycle seems like the worst time for any downstream impacts. Having waited this long, what about planning to get this in shape to merge into main right after the 8.1 release and get it released in 9.0?

@taldcroft

Copy link
Copy Markdown
Member

If @eerovaher or someone else gets this rebased and passing CI again, then I expect it would be easy enough for me or @nstarman to use Claude to check all the coordinated packages with this branch.

@mhvk

mhvk commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Agreed that we might as well wait for 9.0 now (above, we had said we'd do it in a major release).

@pllim pllim modified the milestones: v8.1.0, v9.0.0 Nov 10, 2026
@pllim pllim removed the Close? Tell stale bot that this issue/PR is stale label Nov 10, 2026
@pllim

pllim commented Nov 10, 2026

Copy link
Copy Markdown
Member

OK updated the milestone. Should still clean up the conflicts, which would also reset the stale timer and give you 5 more months.

@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 1 year, 3 months. I plan to close this in a month if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants