diff --git a/.ruff.toml b/.ruff.toml index dd4885dc1ae9..090717d23a17 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -277,7 +277,6 @@ lint.unfixable = [ ] "astropy/timeseries/*" = ["C408"] "astropy/units/*" = [ - "C408", # unnecessary-collection-call "F821", # undefined-name "N812", # lowercase-imported-as-non-lowercase ] diff --git a/astropy/units/equivalencies.py b/astropy/units/equivalencies.py index e0d80da8fca6..0dea6fe30072 100644 --- a/astropy/units/equivalencies.py +++ b/astropy/units/equivalencies.py @@ -52,7 +52,7 @@ class Equivalency(UserList): def __init__(self, equiv_list, name="", kwargs=None): self.data = equiv_list self.name = [name] - self.kwargs = [kwargs] if kwargs is not None else [dict()] + self.kwargs = [kwargs] if kwargs is not None else [{}] def __add__(self, other): if isinstance(other, Equivalency): diff --git a/astropy/units/quantity.py b/astropy/units/quantity.py index 91c46b946516..e92f100d2603 100644 --- a/astropy/units/quantity.py +++ b/astropy/units/quantity.py @@ -675,7 +675,7 @@ def __array_ufunc__(self, function, method, *inputs, **kwargs): return self._result_as_quantity(result, unit, out) except (TypeError, ValueError, AttributeError) as e: - out_normalized = kwargs.get("out", tuple()) + out_normalized = kwargs.get("out", ()) inputs_and_outputs = inputs + out_normalized ignored_ufunc = ( None, diff --git a/astropy/units/quantity_helper/function_helpers.py b/astropy/units/quantity_helper/function_helpers.py index 7df9fd97202e..f5d5b7f63ee9 100644 --- a/astropy/units/quantity_helper/function_helpers.py +++ b/astropy/units/quantity_helper/function_helpers.py @@ -313,7 +313,7 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None): neginf = x._to_own_unit(neginf) return ( (x.view(np.ndarray),), - dict(copy=True, nan=nan, posinf=posinf, neginf=neginf), + {"copy": True, "nan": nan, "posinf": posinf, "neginf": neginf}, x.unit, None, ) @@ -1264,12 +1264,12 @@ def merge_arrays( return ( (arrays,), - dict( - fill_value=fill_value, - flatten=flatten, - usemask=usemask, - asrecarray=asrecarray, - ), + { + "fill_value": fill_value, + "flatten": flatten, + "usemask": usemask, + "asrecarray": asrecarray, + }, unit, None, ) diff --git a/astropy/units/tests/test_equivalencies.py b/astropy/units/tests/test_equivalencies.py index cc02be9022ec..07336b803e5d 100644 --- a/astropy/units/tests/test_equivalencies.py +++ b/astropy/units/tests/test_equivalencies.py @@ -963,7 +963,7 @@ def test_add_equivelencies(): assert isinstance(e1, Equivalency) assert e1.name == ["pixel_scale", "temperature_energy"] assert isinstance(e1.kwargs, list) - assert e1.kwargs == [{"pixscale": 10 * u.arcsec / u.pix}, dict()] + assert e1.kwargs == [{"pixscale": 10 * u.arcsec / u.pix}, {}] e2 = u.pixel_scale(10 * u.arcsec / u.pixel) + [1, 2, 3] assert isinstance(e2, list) diff --git a/astropy/units/tests/test_physical.py b/astropy/units/tests/test_physical.py index 22baaa077029..5f1cb56ad9a0 100644 --- a/astropy/units/tests/test_physical.py +++ b/astropy/units/tests/test_physical.py @@ -267,7 +267,7 @@ def test_physical_type_as_set(unit, expected_set): def test_physical_type_iteration(): """Test iterating through different physical type names.""" - physical_type_names = list(pressure) + physical_type_names = [pressure] assert physical_type_names == ["energy density", "pressure", "stress"] @@ -377,7 +377,7 @@ def test_physical_type_hash(): assert dictionary[length] == 42 -@pytest.mark.parametrize("multiplicand", [list(), 42, 0, -1]) +@pytest.mark.parametrize("multiplicand", [[], 42, 0, -1]) def test_physical_type_multiplication(multiplicand): """ Test that multiplication of a physical type returns `NotImplemented` diff --git a/astropy/units/tests/test_quantity.py b/astropy/units/tests/test_quantity.py index 10a2c31cefa6..05fc969c9f07 100644 --- a/astropy/units/tests/test_quantity.py +++ b/astropy/units/tests/test_quantity.py @@ -1709,8 +1709,8 @@ def __array_finalize__(self, obj): self.my_attr = obj.my_attr self.MyArray = MyArray - self.MyQuantity1 = type("MyQuantity1", (u.Quantity, MyArray), dict(my_attr="1")) - self.MyQuantity2 = type("MyQuantity2", (MyArray, u.Quantity), dict(my_attr="2")) + self.MyQuantity1 = type("MyQuantity1", (u.Quantity, MyArray), {"my_attr": "1"}) + self.MyQuantity2 = type("MyQuantity2", (MyArray, u.Quantity), {"my_attr": "2"}) def test_setup(self): mq1 = self.MyQuantity1(10, u.m) diff --git a/astropy/units/tests/test_quantity_non_ufuncs.py b/astropy/units/tests/test_quantity_non_ufuncs.py index 209835834715..8541ff83968f 100644 --- a/astropy/units/tests/test_quantity_non_ufuncs.py +++ b/astropy/units/tests/test_quantity_non_ufuncs.py @@ -1425,7 +1425,7 @@ def test_histogram(self): [125, 200] * u.cm, weights=weights, value_args=(x.value, [1.25, 2.0]), - value_kwargs=dict(weights=weights.value), + value_kwargs={"weights": weights.value}, expected_units=(weights.unit, x.unit), ) # With weights and density. @@ -1436,7 +1436,7 @@ def test_histogram(self): weights=weights, density=True, value_args=(x.value, [1.25, 2.0]), - value_kwargs=dict(weights=weights.value), + value_kwargs={"weights": weights.value}, expected_units=(weights.unit / x.unit, x.unit), ) @@ -1464,7 +1464,7 @@ def test_histogram_range(self, range): self.x, range=range, value_args=[self.x.value], - value_kwargs=dict(range=self._range_value(range, self.x.unit)), + value_kwargs={"range": self._range_value(range, self.x.unit)}, expected_units=(None, self.x.unit), ) @@ -1524,7 +1524,7 @@ def test_histogram2d(self): y, weights=weights, value_args=(x.value, y.value), - value_kwargs=dict(weights=weights.value), + value_kwargs={"weights": weights.value}, expected_units=(weights.unit, x.unit, y.unit), ) # Check quantity bin sizes. @@ -1545,7 +1545,7 @@ def test_histogram2d(self): y.value, bins=[5, inb2_y], value_args=(x.value, y.value), - value_kwargs=dict(bins=[5, np.array([0, 2.5, 100.0])]), + value_kwargs={"bins": [5, np.array([0, 2.5, 100.0])]}, expected_units=(None, u.one, u.one), ) @@ -1582,12 +1582,12 @@ def test_histogram2d_range(self, range): self.y, range=range, value_args=[self.x.value, self.y.value], - value_kwargs=dict( - range=[ + value_kwargs={ + "range": [ self._range_value(r, un) for (r, un) in zip(range, (self.x.unit, self.y.unit)) ] - ), + }, expected_units=(None, self.x.unit, self.y.unit), ) @@ -1622,7 +1622,7 @@ def test_histogramdd(self): sample, weights=weights, value_args=(sample_values,), - value_kwargs=dict(weights=weights.value), + value_kwargs={"weights": weights.value}, expected_units=(weights.unit, sample_units), ) # Check quantity bin sizes. @@ -1641,7 +1641,7 @@ def test_histogramdd(self): sample_values, bins=[5, inb2_y], value_args=(sample_values,), - value_kwargs=dict(bins=[5, np.array([0, 2.5, 100.0])]), + value_kwargs={"bins": [5, np.array([0, 2.5, 100.0])]}, expected_units=(None, (u.one, u.one)), ) # For quantities, it is probably not that likely one would pass @@ -1696,12 +1696,12 @@ def test_histogramdd_range(self, range): (self.x, self.y), range=range, value_args=[(self.x.value, self.y.value)], - value_kwargs=dict( - range=[ + value_kwargs={ + "range": [ self._range_value(r, un) for (r, un) in zip(range, (self.x.unit, self.y.unit)) ] - ), + }, expected_units=(None, (self.x.unit, self.y.unit)), ) @@ -1914,9 +1914,9 @@ def check2(self, function, *args, **kwargs): @pytest.mark.parametrize( "kwargs", ( - dict(return_index=True, return_inverse=True), - dict(return_counts=True), - dict(return_index=True, return_inverse=True, return_counts=True), + {"return_index": True, "return_inverse": True}, + {"return_count": True}, + {"return_index": True, "return_inverse": True, "return_counts": True}, ), ) def test_unique(self, kwargs): @@ -1926,16 +1926,16 @@ def test_unique(self, kwargs): @pytest.mark.parametrize( "kwargs", ( - dict(axis=0), - dict(axis=1), - dict(return_counts=True, return_inverse=False, axis=1), + {"axis": 0}, + {"axis": 1}, + {"return_counts": True, "return_inverse": False, "axis": 1}, ), ) def test_unique_more_complex(self, kwargs): self.check1(np.unique, **kwargs) @needs_array_function - @pytest.mark.parametrize("kwargs", (dict(), dict(return_indices=True))) + @pytest.mark.parametrize("kwargs", ({}, {"return_indices": True})) def test_intersect1d(self, kwargs): self.check2(np.intersect1d, **kwargs)