Skip to content

Commit 48f448a

Browse files
STY: group large int literals with PEP 515 underscores
Following pylint's bad-number-notation check with --suggest-int-underscore=y, add visual digit grouping to integer literals $\geq$ 1e6: groups of three for decimal (e.g. 2_446_354), groups of four for hex (e.g. 0xFFFF_FFFF). PEP 515 underscores are purely cosmetic — int values are byte-identical.
1 parent 16d229b commit 48f448a

36 files changed

Lines changed: 123 additions & 109 deletions

‎astropy/coordinates/tests/test_matching.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def make_scs():
125125

126126

127127
def test_matching_method():
128-
with NumpyRNGContext(987654321):
128+
with NumpyRNGContext(987_654_321):
129129
cmatch = ICRS(
130130
np.random.rand(20) * 360.0 * u.degree,
131131
(np.random.rand(20) * 180.0 - 90.0) * u.degree,

‎astropy/coordinates/tests/test_sky_coord.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def test_repr_altaz():
769769

770770
expected_el_repr = "(-2309223.0, -3695529.0, -4641767.0)"
771771

772-
loc = EarthLocation(-2309223 * u.m, -3695529 * u.m, -4641767 * u.m)
772+
loc = EarthLocation(-2_309_223 * u.m, -3_695_529 * u.m, -4_641_767 * u.m)
773773
time = Time("2005-03-21 00:00:00")
774774
sc4 = sc2.transform_to(AltAz(location=loc, obstime=time))
775775
assert repr(sc4).startswith(
@@ -1414,7 +1414,7 @@ def test_search_around():
14141414
"""
14151415
from astropy.utils import NumpyRNGContext
14161416

1417-
with NumpyRNGContext(987654321):
1417+
with NumpyRNGContext(987_654_321):
14181418
sc1 = SkyCoord(
14191419
np.random.rand(20) * 360.0 * u.degree,
14201420
(np.random.rand(20) * 180.0 - 90.0) * u.degree,
@@ -1459,7 +1459,7 @@ def test_guess_from_table():
14591459
from astropy.utils import NumpyRNGContext
14601460

14611461
tab = Table()
1462-
with NumpyRNGContext(987654321):
1462+
with NumpyRNGContext(987_654_321):
14631463
tab.add_column(Column(data=np.random.rand(10), unit="deg", name="RA[J2000]"))
14641464
tab.add_column(Column(data=np.random.rand(10), unit="deg", name="DEC[J2000]"))
14651465

‎astropy/coordinates/tests/test_solar_system.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def test_regression_15611():
430430
# type 3 SPICE kernel
431431
ephemeris_file = get_pkg_data_filename("coordinates/230965_2004XA192_nima_v6.bsp")
432432
# KBO 2004 XA192
433-
pair = (10, 20230965)
433+
pair = (10, 20_230_965)
434434
t = Time("2023-11-11T03:59:24")
435435
# get_body_barycentric should not raise an error
436436
get_body_barycentric([pair], t, ephemeris=ephemeris_file)

‎astropy/coordinates/tests/test_velocity_corrs.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_barycorr(input_radecs):
208208

209209

210210
def test_rvcorr_multiple_obstimes_onskycoord():
211-
loc = EarthLocation(-2309223 * u.m, -3695529 * u.m, -4641767 * u.m)
211+
loc = EarthLocation(-2_309_223 * u.m, -3_695_529 * u.m, -4_641_767 * u.m)
212212
arrtime = Time("2005-03-21 00:00:00") + np.linspace(-1, 1, 10) * u.day
213213

214214
sc = SkyCoord(1 * u.deg, 2 * u.deg, 100 * u.kpc, obstime=arrtime, location=loc)
@@ -224,7 +224,7 @@ def test_rvcorr_multiple_obstimes_onskycoord():
224224

225225

226226
def test_invalid_argument_combos():
227-
loc = EarthLocation(-2309223 * u.m, -3695529 * u.m, -4641767 * u.m)
227+
loc = EarthLocation(-2_309_223 * u.m, -3_695_529 * u.m, -4_641_767 * u.m)
228228
time = Time("2005-03-21 00:00:00")
229229
timel = Time("2005-03-21 00:00:00", location=loc)
230230

@@ -334,7 +334,7 @@ def test_regression_10094():
334334
# CTIO location as used in Wright & Eastmann
335335
xyz = u.Quantity([1.8149853e6, -5.2139168e6, -3.1877381e6], u.m)
336336
obs = EarthLocation(*xyz)
337-
times = Time(2400000, reduced_jds, format="jd")
337+
times = Time(2_400_000, reduced_jds, format="jd")
338338
tempo2 = tempo2 * speed_of_light
339339
barycorr = barycorr * speed_of_light
340340
astropy = tauCet.radial_velocity_correction(location=obs, obstime=times)

‎astropy/extern/configobj/validate.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def numToDottedQuad(num):
344344
import socket, struct
345345

346346
# no need to intercept here, 4294967295L is fine
347-
if num > long(4294967295) or num < 0:
347+
if num > long(4_294_967_295) or num < 0:
348348
raise ValueError('Not a good numeric IP: %s' % num)
349349
try:
350350
return socket.inet_ntoa(

‎astropy/io/ascii/core.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class MaskedConstant(np.ma.core.MaskedConstant):
175175
def __hash__(self):
176176
"""All instances of this class shall have the same hash."""
177177
# Any large number will do.
178-
return 1234567890
178+
return 1_234_567_890
179179

180180
def __copy__(self) -> Self:
181181
"""This is a singleton so just return self."""

‎astropy/io/ascii/tests/test_types.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_ipac_read_long_columns():
6363

6464
# assert oid, as a long column, is int64
6565
oid = dat["oid"]
66-
assert oid[0] == 90000000000000001
66+
assert oid[0] == 90_000_000_000_000_001
6767
assert oid.dtype.kind == "i"
6868
assert oid.dtype.itemsize == 8
6969

@@ -90,7 +90,7 @@ def test_large_integers(fast):
9090
# assert `num`` is exactly 64bit int
9191
assert dat["num"].dtype.kind == "i"
9292
assert dat["num"].dtype.itemsize == 8
93-
assert dat["num"][0] == 110000000000000001
93+
assert dat["num"][0] == 110_000_000_000_000_001
9494

9595
# assert `cadence` is exactly 64bit int, even though the values are small numbers.
9696
assert dat["cadence"].dtype.kind == "i"

‎astropy/io/fits/hdu/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,12 +1459,12 @@ def _compute_checksum(self, data, sum32=0):
14591459
piece = piece[:-extra]
14601460
s += int(piece.view(">u4").sum(dtype="u8"))
14611461
while hi := (s >> 32):
1462-
s = (s & 0xFFFFFFFF) + hi
1462+
s = (s & 0xFFFF_FFFF) + hi
14631463
return np.uint32(s)
14641464

14651465
# _MASK and _EXCLUDE used for encoding the checksum value into a character
14661466
# string.
1467-
_MASK = [0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF]
1467+
_MASK = [0xFF00_0000, 0x00FF_0000, 0x0000FF00, 0x000000FF]
14681468

14691469
_EXCLUDE = [0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40,
14701470
0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60] # fmt: skip

‎astropy/io/fits/hdu/compressed/_tiled_compression.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"NOCOMPRESS": NoCompress,
2626
}
2727

28-
DEFAULT_ZBLANK = -2147483648
28+
DEFAULT_ZBLANK = -2_147_483_648
2929

3030

3131
__all__ = [

‎astropy/io/fits/hdu/compressed/tests/test_compressed.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ def test_reserved_keywords_stripped(tmp_path):
14891489
tmp_path / "compressed.fits", disable_image_compression=True
14901490
) as hduc:
14911491
hduc[1].header["THEAP"] = hduc[1].header["NAXIS1"] * hduc[1].header["NAXIS2"]
1492-
hduc[1].header["ZBLANK"] = 1231212
1492+
hduc[1].header["ZBLANK"] = 1_231_212
14931493
hduc[1].header["ZSCALE"] = 2
14941494
hduc[1].header["ZZERO"] = 10
14951495
hduc[1].writeto(tmp_path / "compressed_with_extra.fits")

0 commit comments

Comments
 (0)