-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Change the quotes in the repr of units from "
to '
#18509
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
base: main
Are you sure you want to change the base?
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.
|
>>> su.field_names | ||
(['f0', ('f0', 'f1')], 'f1') | ||
>>> su['f1'] | ||
Unit("yr") | ||
Unit('yr') |
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.
Notice that the quotes are now consistent with the quotes in field_names
.
"^Object with NFKC normalized name 'h' already exists in given namespace " | ||
r'\(Unit\("h"\)\)\.$' | ||
r"\(Unit\('h'\)\)\.$" |
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.
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.
{'l': Unit("deg"), 'b': Unit("deg")} | ||
{'l': Unit('deg'), 'b': Unit('deg')} |
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.
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.
9a13d57
to
4485236
Compare
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.
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.
Nobody has objected, so we can move forward with this.
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 |
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.
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.
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. |
So please DO NOT merge just yet. |
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. |
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.
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.
- Do this for a Major.0 release.
- Add to the what'snew a link to
pytest-doctestplus
's instructions on how to restrict doctests to specific versions of Astropy.
Agreed. One quick-ish test of impact would be to see how many breakages this causes in the coordinated packages.
The only mention I could find of quoting in PEP8 is this:
Would you be recommending that downstream packages pin astropy at 7.2 for doctest forever? |
It would be the other way around, change to 8.0 and exclude 7.2 from tests. Note that, as I wrote above, I think the impact will actually be quite minor - it only appears when one explicitly displays a unit, in all container classes ( Anyway, the above feeling that risks are not that big is why I had a +0.5. But I think you are right it behooves us to test this on the coordinated packages at least (actually, it might not be bad to have a special CI entry + label that does exactly that). |
I was assuming this PR goes into 8.0 and that 7.2 is the last one using double quotes. Then either downstream pins at 7.2 forever or at some point they do the work of fixing doctests to test against the current release. Am I still not understanding?
Another question is if the astropy notebook tutorials will be impacted. Are they regression tested? |
That's correct. And when they do the work, they can pin >=8.0 (if they still support older astropy versions). |
Given the discussions about v8.0 milestone and potentially breaking downstream, I am updating the milestone and turning this into draft for now. Thanks for your understanding. |
Answering #18509 (comment)
A notebook would prefer using |
Description
The repr of Python strings uses
'
, not"
, so to be consistent with that the repr ofastropy
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.