diff --git a/.ruff.toml b/.ruff.toml index c09643e4c4ef..dd4885dc1ae9 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -242,7 +242,6 @@ lint.unfixable = [ "astropy/constants/*" = ["N817"] # camelcase-imported-as-acronym "astropy/convolution/*" = [] "astropy/coordinates/*" = [ - "C408", # unnecessary-collection-call "DTZ007", # call-datetime-strptime-without-zone ] "astropy/cosmology/*" = [ diff --git a/astropy/coordinates/builtin_frames/galactocentric.py b/astropy/coordinates/builtin_frames/galactocentric.py index d68b1cc5b10e..06f9a9c783e8 100644 --- a/astropy/coordinates/builtin_frames/galactocentric.py +++ b/astropy/coordinates/builtin_frames/galactocentric.py @@ -152,7 +152,7 @@ class galactocentric_frame_defaults(ScienceState): _latest_value = "v4.0" _value = None _references = None - _state = dict() # all other data + _state = {} # all other data # Note: _StateProxy() produces read-only view of enclosed mapping. _registry = { @@ -284,11 +284,11 @@ def validate(cls, value): elif isinstance(value, Galactocentric): # turn the frame instance into a dict of frame attributes - parameters = dict() + parameters = {} for k in value.frame_attributes: parameters[k] = getattr(value, k) cls._references = value.frame_attribute_references.copy() - cls._state = dict(parameters=parameters, references=cls._references) + cls._state = {"parameters": parameters, "references": cls._references} else: raise ValueError( @@ -325,7 +325,7 @@ def register( references = references or {} # None -> {} - state = dict(parameters=parameters, references=references) + state = {"parameters": parameters, "references": references} state.update(meta) # meta never has keys "parameters" or "references" cls._registry[name] = state diff --git a/astropy/coordinates/polarization.py b/astropy/coordinates/polarization.py index 45d71430892e..5bc9ca2ca43f 100644 --- a/astropy/coordinates/polarization.py +++ b/astropy/coordinates/polarization.py @@ -123,7 +123,7 @@ def new_like(self, cols, length, metadata_conflicts="warn", name=None): shape = (length,) + attrs.pop("shape") data = np.zeros(shape=shape, dtype=attrs.pop("dtype")) # Get arguments needed to reconstruct class - out = self._construct_from_dict(dict(value=data)) + out = self._construct_from_dict({"value": data}) # Set remaining info attributes for attr, value in attrs.items(): diff --git a/astropy/coordinates/representation/base.py b/astropy/coordinates/representation/base.py index ceccfe4b1fd4..b03059d562f7 100644 --- a/astropy/coordinates/representation/base.py +++ b/astropy/coordinates/representation/base.py @@ -686,7 +686,7 @@ def _validate_differentials(self, differentials): # Now handle the actual validation of any specified differential classes if differentials is None: - differentials = dict() + differentials = {} elif isinstance(differentials, BaseDifferential): # We can't handle auto-determining the key for this combo @@ -807,7 +807,7 @@ def _re_represent_differentials(self, new_rep, differential_class): attached differentials converted to the new differential classes. """ if differential_class is None: - return dict() + return {} if not self.differentials and differential_class: raise ValueError("No differentials associated with this representation!") @@ -829,7 +829,7 @@ def _re_represent_differentials(self, new_rep, differential_class): f"representation object ({self.differentials})" ) - new_diffs = dict() + new_diffs = {} for k in self.differentials: diff = self.differentials[k] try: diff --git a/astropy/coordinates/tests/test_arrays.py b/astropy/coordinates/tests/test_arrays.py index 65fce289b91c..0f9b6672ec1d 100644 --- a/astropy/coordinates/tests/test_arrays.py +++ b/astropy/coordinates/tests/test_arrays.py @@ -267,7 +267,7 @@ def test_array_len(): c = ICRS(0 * u.deg, 0 * u.deg) len(c) - assert c.shape == tuple() + assert c.shape == () def test_array_eq(): diff --git a/astropy/coordinates/tests/test_erfa_astrom.py b/astropy/coordinates/tests/test_erfa_astrom.py index e22672b2ffb1..bed6653ab615 100644 --- a/astropy/coordinates/tests/test_erfa_astrom.py +++ b/astropy/coordinates/tests/test_erfa_astrom.py @@ -77,7 +77,7 @@ def test_interpolation_nd(): interp_provider = ErfaAstromInterpolator(300 * u.s) provider = ErfaAstrom() - for shape in [tuple(), (1,), (10,), (3, 2), (2, 10, 5), (4, 5, 3, 2)]: + for shape in [(), (1,), (10,), (3, 2), (2, 10, 5), (4, 5, 3, 2)]: # create obstimes of the desired shapes delta_t = np.linspace(0, 12, np.prod(shape, dtype=int)) * u.hour obstime = (Time("2020-01-01T18:00") + delta_t).reshape(shape) diff --git a/astropy/coordinates/tests/test_frames.py b/astropy/coordinates/tests/test_frames.py index d3e478418520..17ac651dd648 100644 --- a/astropy/coordinates/tests/test_frames.py +++ b/astropy/coordinates/tests/test_frames.py @@ -1553,7 +1553,7 @@ def test_galactocentric_defaults(): with galactocentric_frame_defaults.set("latest"): params = galactocentric_frame_defaults.validate(galcen_latest) references = galcen_latest.frame_attribute_references - state = dict(parameters=params, references=references) + state = {"parameters": params, "references": references} assert galactocentric_frame_defaults.parameters == params assert galactocentric_frame_defaults.references == references diff --git a/astropy/coordinates/tests/test_funcs.py b/astropy/coordinates/tests/test_funcs.py index fb8cb90a1f33..94cc5cc1d09f 100644 --- a/astropy/coordinates/tests/test_funcs.py +++ b/astropy/coordinates/tests/test_funcs.py @@ -70,7 +70,7 @@ def test_constellations(recwarn): assert res == "Ursa Major" assert res_short == "UMa" - assert isinstance(res, str) or getattr(res, "shape", None) == tuple() + assert isinstance(res, str) or getattr(res, "shape", None) == () # these are taken from the ReadMe for Roman 1987 ras = [9, 23.5, 5.12, 9.4555, 12.8888, 15.6687, 19, 6.2222] @@ -84,7 +84,7 @@ def test_constellations(recwarn): # non-ASCII character boores = get_constellation(SkyCoord(15 * u.hour, 30 * u.deg, frame="icrs")) assert boores == "Boötes" - assert isinstance(boores, str) or getattr(boores, "shape", None) == tuple() + assert isinstance(boores, str) or getattr(boores, "shape", None) == () @pytest.mark.xfail diff --git a/astropy/coordinates/tests/test_name_resolve.py b/astropy/coordinates/tests/test_name_resolve.py index 9bcdeb1a5a39..04fbda7d1faa 100644 --- a/astropy/coordinates/tests/test_name_resolve.py +++ b/astropy/coordinates/tests/test_name_resolve.py @@ -22,7 +22,7 @@ ) from astropy.coordinates.sky_coordinate import SkyCoord -_cached_ngc3642 = dict() +_cached_ngc3642 = {} _cached_ngc3642[ "simbad" ] = """# NGC 3642 #Q22523669 @@ -75,7 +75,7 @@ #====Done (2013-Feb-12,16:39:48z)====""" -_cached_castor = dict() +_cached_castor = {} _cached_castor[ "all" ] = """# castor #Q22524249 diff --git a/astropy/coordinates/tests/test_regression.py b/astropy/coordinates/tests/test_regression.py index 8233dbaf67c0..5f74f6a47dcd 100644 --- a/astropy/coordinates/tests/test_regression.py +++ b/astropy/coordinates/tests/test_regression.py @@ -88,18 +88,18 @@ def test_regression_3920(): aa = AltAz(location=loc, obstime=time) sc = SkyCoord(10 * u.deg, 3 * u.deg) - assert sc.transform_to(aa).shape == tuple() + assert sc.transform_to(aa).shape == () # That part makes sense: the input is a scalar so the output is too sc2 = SkyCoord(10 * u.deg, 3 * u.deg, 1 * u.AU) - assert sc2.transform_to(aa).shape == tuple() + assert sc2.transform_to(aa).shape == () # in 3920 that assert fails, because the shape is (1,) # check that the same behavior occurs even if transform is from low-level classes icoo = ICRS(sc.data) icoo2 = ICRS(sc2.data) - assert icoo.transform_to(aa).shape == tuple() - assert icoo2.transform_to(aa).shape == tuple() + assert icoo.transform_to(aa).shape == () + assert icoo2.transform_to(aa).shape == () def test_regression_3938(): @@ -443,7 +443,7 @@ def test_regression_5743(): sc = SkyCoord( [5, 10], [20, 30], unit=u.deg, obstime=["2017-01-01T00:00", "2017-01-01T00:10"] ) - assert sc[0].obstime.shape == tuple() + assert sc[0].obstime.shape == () def test_regression_5889_5890(): diff --git a/astropy/coordinates/tests/test_representation.py b/astropy/coordinates/tests/test_representation.py index 8a2e3d76f903..b4621ca20be4 100644 --- a/astropy/coordinates/tests/test_representation.py +++ b/astropy/coordinates/tests/test_representation.py @@ -120,7 +120,7 @@ def test_transform(self): # let's also check with differentials dif = RadialDifferential(d_distance=-3 * u.km / u.s) - rep = rep.with_differentials(dict(s=dif)) + rep = rep.with_differentials({"s": dif}) newrep = rep.transform(matrix) assert newrep.distance == 30 * u.kpc diff --git a/astropy/coordinates/tests/test_representation_arithmetic.py b/astropy/coordinates/tests/test_representation_arithmetic.py index 8294bc1a3f14..e880f08c25d5 100644 --- a/astropy/coordinates/tests/test_representation_arithmetic.py +++ b/astropy/coordinates/tests/test_representation_arithmetic.py @@ -175,7 +175,7 @@ def test_mul_div(self, representation): with pytest.raises(TypeError): in_rep * in_rep with pytest.raises(TypeError): - dict() * in_rep + {} * in_rep def test_mul_div_unit_spherical(self): s1 = self.unit_spherical * self.distance diff --git a/astropy/coordinates/tests/test_sky_coord_velocities.py b/astropy/coordinates/tests/test_sky_coord_velocities.py index dc372ad2e11a..164beab22a79 100644 --- a/astropy/coordinates/tests/test_sky_coord_velocities.py +++ b/astropy/coordinates/tests/test_sky_coord_velocities.py @@ -157,7 +157,7 @@ def sc(request): incldist, inclrv = request.param args = [1 * u.deg, 2 * u.deg] - kwargs = dict(pm_dec=1 * u.mas / u.yr, pm_ra_cosdec=2 * u.mas / u.yr) + kwargs = {"pm_dec": 1 * u.mas / u.yr, "pm_ra_cosdec": 2 * u.mas / u.yr} if incldist: kwargs["distance"] = 213.4 * u.pc if inclrv: @@ -291,17 +291,17 @@ def test_cartesian_to_spherical(sph_type): @pytest.mark.parametrize( "diff_info, diff_cls", [ - (dict(radial_velocity=[20, 30] * u.km / u.s), RadialDifferential), + ({"radial_velocity": [20, 30] * u.km / u.s}, RadialDifferential), ( - dict( - pm_ra=[2, 3] * u.mas / u.yr, - pm_dec=[-3, -4] * u.mas / u.yr, - differential_type="unitspherical", - ), + { + "pm_ra": [2, 3] * u.mas / u.yr, + "pm_dec": [-3, -4] * u.mas / u.yr, + "differential_type": "unitspherical", + }, UnitSphericalDifferential, ), ( - dict(pm_ra_cosdec=[2, 3] * u.mas / u.yr, pm_dec=[-3, -4] * u.mas / u.yr), + {"pm_ra_cosdec": [2, 3] * u.mas / u.yr, "pm_dec": [-3, -4] * u.mas / u.yr}, UnitSphericalCosLatDifferential, ), ], diff --git a/astropy/coordinates/tests/test_spectral_coordinate.py b/astropy/coordinates/tests/test_spectral_coordinate.py index a0f8bd613008..d174ae4677fc 100644 --- a/astropy/coordinates/tests/test_spectral_coordinate.py +++ b/astropy/coordinates/tests/test_spectral_coordinate.py @@ -905,10 +905,10 @@ def test_shift_to_rest_star_withobserver(): @pytest.mark.parametrize( "sc_kwargs", [ - dict(radial_velocity=0 * u.km / u.s), - dict(observer=gcrs_origin, radial_velocity=0 * u.km / u.s), - dict(target=gcrs_origin, radial_velocity=0 * u.km / u.s), - dict(observer=gcrs_origin, target=gcrs_not_origin), + {"radial_velocity": 0 * u.km / u.s}, + {"observer": gcrs_origin, "radial_velocity": 0 * u.km / u.s}, + {"target": gcrs_origin, "radial_velocity": 0 * u.km / u.s}, + {"observer": gcrs_origin, "target": gcrs_not_origin}, ], ) def test_los_shift(sc_kwargs):