From 47817f16073223fcb93f1557dddf497cc98e0c5e Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Thu, 13 Jul 2023 16:34:02 -0400 Subject: [PATCH 1/4] Make class variables immutable --- asdf_astropy/converters/coordinates/angle.py | 15 +++---- .../converters/coordinates/earth_location.py | 5 +-- asdf_astropy/converters/coordinates/frame.py | 5 +-- .../converters/coordinates/representation.py | 7 ++-- .../converters/coordinates/sky_coord.py | 5 +-- .../converters/coordinates/spectral_coord.py | 5 +-- asdf_astropy/converters/fits/fits.py | 8 ++-- asdf_astropy/converters/table/table.py | 19 ++++----- asdf_astropy/converters/time/time.py | 5 +-- asdf_astropy/converters/time/time_delta.py | 5 +-- asdf_astropy/converters/transform/compound.py | 7 ++-- .../converters/transform/functional_models.py | 7 ++-- asdf_astropy/converters/transform/mappings.py | 15 +++---- .../converters/transform/math_functions.py | 5 +-- .../converters/transform/polynomial.py | 40 +++++++++---------- .../converters/transform/properties.py | 8 ++-- .../converters/transform/rotations.py | 14 +++---- asdf_astropy/converters/transform/spline.py | 4 +- asdf_astropy/converters/transform/tabular.py | 7 ++-- asdf_astropy/converters/unit/equivalency.py | 5 +-- asdf_astropy/converters/unit/magunit.py | 7 +--- asdf_astropy/converters/unit/quantity.py | 7 ++-- asdf_astropy/converters/unit/unit.py | 9 ++--- 23 files changed, 93 insertions(+), 121 deletions(-) diff --git a/asdf_astropy/converters/coordinates/angle.py b/asdf_astropy/converters/coordinates/angle.py index e5016e7a..bb9f19f4 100644 --- a/asdf_astropy/converters/coordinates/angle.py +++ b/asdf_astropy/converters/coordinates/angle.py @@ -2,9 +2,8 @@ class AngleConverter(QuantityConverter): - tags = ["tag:astropy.org:astropy/coordinates/angle-*"] - - types = ["astropy.coordinates.angles.Angle"] + tags = ("tag:astropy.org:astropy/coordinates/angle-*",) + types = ("astropy.coordinates.angles.Angle",) def from_yaml_tree(self, node, tag, ctx): from astropy.coordinates.angles import Angle @@ -13,9 +12,8 @@ def from_yaml_tree(self, node, tag, ctx): class LatitudeConverter(QuantityConverter): - tags = ["tag:astropy.org:astropy/coordinates/latitude-*"] - - types = ["astropy.coordinates.angles.Latitude"] + tags = ("tag:astropy.org:astropy/coordinates/latitude-*",) + types = ("astropy.coordinates.angles.Latitude",) def from_yaml_tree(self, node, tag, ctx): from astropy.coordinates.angles import Latitude @@ -24,9 +22,8 @@ def from_yaml_tree(self, node, tag, ctx): class LongitudeConverter(QuantityConverter): - tags = ["tag:astropy.org:astropy/coordinates/longitude-*"] - - types = ["astropy.coordinates.angles.Longitude"] + tags = ("tag:astropy.org:astropy/coordinates/longitude-*",) + types = ("astropy.coordinates.angles.Longitude",) def to_yaml_tree(self, obj, tag, ctx): tree = super().to_yaml_tree(obj, tag, ctx) diff --git a/asdf_astropy/converters/coordinates/earth_location.py b/asdf_astropy/converters/coordinates/earth_location.py index 2dabe9ab..74200439 100644 --- a/asdf_astropy/converters/coordinates/earth_location.py +++ b/asdf_astropy/converters/coordinates/earth_location.py @@ -2,9 +2,8 @@ class EarthLocationConverter(Converter): - tags = ["tag:astropy.org:astropy/coordinates/earthlocation-*"] - - types = ["astropy.coordinates.earth.EarthLocation"] + tags = ("tag:astropy.org:astropy/coordinates/earthlocation-*",) + types = ("astropy.coordinates.earth.EarthLocation",) def to_yaml_tree(self, obj, tag, ctx): return obj.info._represent_as_dict() diff --git a/asdf_astropy/converters/coordinates/frame.py b/asdf_astropy/converters/coordinates/frame.py index 1dce77af..9bbdf71c 100644 --- a/asdf_astropy/converters/coordinates/frame.py +++ b/asdf_astropy/converters/coordinates/frame.py @@ -54,11 +54,10 @@ def from_yaml_tree(self, node, tag, ctx): class LegacyICRSConverter(Converter): - tags = ["tag:astropy.org:astropy/coordinates/frames/icrs-1.0.0"] - + tags = ("tag:astropy.org:astropy/coordinates/frames/icrs-1.0.0",) # Leave the types list empty so that the 1.1.0 ICRS converter # is used on write. - types = [] + types = () def to_yaml_tree(self, obj, tag, ctx): from astropy.units import Quantity diff --git a/asdf_astropy/converters/coordinates/representation.py b/asdf_astropy/converters/coordinates/representation.py index 1fa05439..7c30ff1a 100644 --- a/asdf_astropy/converters/coordinates/representation.py +++ b/asdf_astropy/converters/coordinates/representation.py @@ -2,9 +2,8 @@ class RepresentationConverter(Converter): - tags = ["tag:astropy.org:astropy/coordinates/representation-*"] - - types = [ + tags = ("tag:astropy.org:astropy/coordinates/representation-*",) + types = ( "astropy.coordinates.representation.CartesianDifferential", "astropy.coordinates.representation.CartesianRepresentation", "astropy.coordinates.representation.CylindricalDifferential", @@ -34,7 +33,7 @@ class RepresentationConverter(Converter): "astropy.coordinates.representation.spherical.UnitSphericalRepresentation", "astropy.coordinates.representation.spherical.UnitSphericalDifferential", "astropy.coordinates.representation.spherical.UnitSphericalCosLatDifferential", - ] + ) def to_yaml_tree(self, obj, tag, ctx): components = {} diff --git a/asdf_astropy/converters/coordinates/sky_coord.py b/asdf_astropy/converters/coordinates/sky_coord.py index 1f041d21..6310b863 100644 --- a/asdf_astropy/converters/coordinates/sky_coord.py +++ b/asdf_astropy/converters/coordinates/sky_coord.py @@ -2,9 +2,8 @@ class SkyCoordConverter(Converter): - tags = ["tag:astropy.org:astropy/coordinates/skycoord-*"] - - types = ["astropy.coordinates.sky_coordinate.SkyCoord"] + tags = ("tag:astropy.org:astropy/coordinates/skycoord-*",) + types = ("astropy.coordinates.sky_coordinate.SkyCoord",) def to_yaml_tree(self, obj, tag, ctx): return obj.info._represent_as_dict() diff --git a/asdf_astropy/converters/coordinates/spectral_coord.py b/asdf_astropy/converters/coordinates/spectral_coord.py index f4c5bae5..680825fa 100644 --- a/asdf_astropy/converters/coordinates/spectral_coord.py +++ b/asdf_astropy/converters/coordinates/spectral_coord.py @@ -3,9 +3,8 @@ class SpectralCoordConverter(Converter): - tags = ["tag:astropy.org:astropy/coordinates/spectralcoord-*"] - - types = ["astropy.coordinates.spectral_coordinate.SpectralCoord"] + tags = ("tag:astropy.org:astropy/coordinates/spectralcoord-*",) + types = ("astropy.coordinates.spectral_coordinate.SpectralCoord",) def to_yaml_tree(self, obj, tag, ctx): node = { diff --git a/asdf_astropy/converters/fits/fits.py b/asdf_astropy/converters/fits/fits.py index c9d65f77..1bd45d7e 100644 --- a/asdf_astropy/converters/fits/fits.py +++ b/asdf_astropy/converters/fits/fits.py @@ -66,10 +66,10 @@ def from_yaml_tree(self, node, tag, ctx): class AsdfFitsConverter(FitsConverter): - tags = ["tag:stsci.edu:asdf/fits/fits-*"] - types = [] + tags = ("tag:stsci.edu:asdf/fits/fits-*",) + types = () class AstropyFitsConverter(FitsConverter): - tags = ["tag:astropy.org:astropy/fits/fits-*"] - types = ["astropy.io.fits.hdu.hdulist.HDUList"] + tags = ("tag:astropy.org:astropy/fits/fits-*",) + types = ("astropy.io.fits.hdu.hdulist.HDUList",) diff --git a/asdf_astropy/converters/table/table.py b/asdf_astropy/converters/table/table.py index 919336c0..bf4f72da 100644 --- a/asdf_astropy/converters/table/table.py +++ b/asdf_astropy/converters/table/table.py @@ -3,12 +3,11 @@ class ColumnConverter(Converter): - tags = ["tag:stsci.edu:asdf/core/column-*"] - - types = [ + tags = ("tag:stsci.edu:asdf/core/column-*",) + types = ( "astropy.table.column.Column", "astropy.table.column.MaskedColumn", - ] + ) def to_yaml_tree(self, obj, tag, ctx): node = {"data": obj.data, "name": obj.name} @@ -46,9 +45,8 @@ def from_yaml_tree(self, node, tag, ctx): class AsdfTableConverter(Converter): - tags = ["tag:stsci.edu:asdf/core/table-*"] - - types = [] + tags = ("tag:stsci.edu:asdf/core/table-*",) + types = () def to_yaml_tree(self, obj, tag, ctx): msg = "astropy does not support writing astropy.table.Table with the ASDF table-1.0.0 tag" @@ -61,12 +59,11 @@ def from_yaml_tree(self, node, tag, ctx): class AstropyTableConverter(Converter): - tags = ["tag:astropy.org:astropy/table/table-*"] - - types = [ + tags = ("tag:astropy.org:astropy/table/table-*",) + types = ( "astropy.table.table.Table", "astropy.table.table.QTable", - ] + ) def to_yaml_tree(self, obj, tag, ctx): from astropy.table import QTable diff --git a/asdf_astropy/converters/time/time.py b/asdf_astropy/converters/time/time.py index 41778a52..188bb652 100644 --- a/asdf_astropy/converters/time/time.py +++ b/asdf_astropy/converters/time/time.py @@ -12,9 +12,8 @@ class TimeConverter(Converter): - tags = ["tag:stsci.edu:asdf/time/time-*"] - - types = ["astropy.time.core.Time"] + tags = ("tag:stsci.edu:asdf/time/time-*",) + types = ("astropy.time.core.Time",) def to_yaml_tree(self, obj, tag, ctx): from astropy.time import Time diff --git a/asdf_astropy/converters/time/time_delta.py b/asdf_astropy/converters/time/time_delta.py index 16be6947..e7886248 100644 --- a/asdf_astropy/converters/time/time_delta.py +++ b/asdf_astropy/converters/time/time_delta.py @@ -2,9 +2,8 @@ class TimeDeltaConverter(Converter): - tags = ["tag:astropy.org:astropy/time/timedelta-*"] - - types = ["astropy.time.core.TimeDelta"] + tags = ("tag:astropy.org:astropy/time/timedelta-*",) + types = ("astropy.time.core.TimeDelta",) def to_yaml_tree(self, obj, tag, ctx): return obj.info._represent_as_dict() diff --git a/asdf_astropy/converters/transform/compound.py b/asdf_astropy/converters/transform/compound.py index 99a3c42c..2a434b2d 100644 --- a/asdf_astropy/converters/transform/compound.py +++ b/asdf_astropy/converters/transform/compound.py @@ -34,7 +34,7 @@ class CompoundConverter(TransformConverterBase): ASDF serialization support for CompoundModel. """ - tags = [ + tags = ( "tag:stsci.edu:asdf/transform/add-*", "tag:stsci.edu:asdf/transform/subtract-*", "tag:stsci.edu:asdf/transform/multiply-*", @@ -43,9 +43,8 @@ class CompoundConverter(TransformConverterBase): "tag:stsci.edu:asdf/transform/compose-*", "tag:stsci.edu:asdf/transform/concatenate-*", "tag:stsci.edu:asdf/transform/fix_inputs-*", - ] - - types = ["astropy.modeling.core.CompoundModel"] + ) + types = ("astropy.modeling.core.CompoundModel",) def select_tag(self, model, tags, ctx): tag_name = _OPERATOR_TO_TAG_NAME[model.op] diff --git a/asdf_astropy/converters/transform/functional_models.py b/asdf_astropy/converters/transform/functional_models.py index becab943..b2186532 100644 --- a/asdf_astropy/converters/transform/functional_models.py +++ b/asdf_astropy/converters/transform/functional_models.py @@ -14,12 +14,11 @@ class ConstantConverter(TransformConverterBase): # previously all values were 1D. _2D_MIN_VERSION = parse_version("1.4.0") - tags = ["tag:stsci.edu:asdf/transform/constant-*"] - - types = [ + tags = ("tag:stsci.edu:asdf/transform/constant-*",) + types = ( "astropy.modeling.functional_models.Const1D", "astropy.modeling.functional_models.Const2D", - ] + ) def to_yaml_tree_transform(self, model, tag, ctx): from astropy.modeling.functional_models import Const1D, Const2D diff --git a/asdf_astropy/converters/transform/mappings.py b/asdf_astropy/converters/transform/mappings.py index 0434e75f..a905c9d3 100644 --- a/asdf_astropy/converters/transform/mappings.py +++ b/asdf_astropy/converters/transform/mappings.py @@ -8,9 +8,8 @@ class IdentityConverter(TransformConverterBase): ASDF support for serializing the Identity model. """ - tags = ["tag:stsci.edu:asdf/transform/identity-*"] - - types = ["astropy.modeling.mappings.Identity"] + tags = ("tag:stsci.edu:asdf/transform/identity-*",) + types = ("astropy.modeling.mappings.Identity",) def to_yaml_tree_transform(self, model, tag, ctx): node = {} @@ -29,9 +28,8 @@ class RemapAxesConverter(TransformConverterBase): ASDF support for serializing the Mapping model """ - tags = ["tag:stsci.edu:asdf/transform/remap_axes-*"] - - types = ["astropy.modeling.mappings.Mapping"] + tags = ("tag:stsci.edu:asdf/transform/remap_axes-*",) + types = ("astropy.modeling.mappings.Mapping",) def to_yaml_tree_transform(self, model, tag, ctx): node = {"mapping": list(model.mapping)} @@ -53,9 +51,8 @@ class UnitsMappingConverter(Converter): from other models. """ - tags = ["tag:astropy.org:astropy/transform/units_mapping-*"] - - types = ["astropy.modeling.mappings.UnitsMapping"] + tags = ("tag:astropy.org:astropy/transform/units_mapping-*",) + types = ("astropy.modeling.mappings.UnitsMapping",) def to_yaml_tree(self, model, tag, ctx): node = {} diff --git a/asdf_astropy/converters/transform/math_functions.py b/asdf_astropy/converters/transform/math_functions.py index 8636fdf8..ce82cc2b 100644 --- a/asdf_astropy/converters/transform/math_functions.py +++ b/asdf_astropy/converters/transform/math_functions.py @@ -55,9 +55,8 @@ class MathFunctionsConverter(TransformConverterBase): each of which corresponds to a numpy ufunc. """ - tags = ["tag:stsci.edu:asdf/transform/math_functions-*"] - - types = ["astropy.modeling.math_functions." + m for m in _MODEL_NAMES] + tags = ("tag:stsci.edu:asdf/transform/math_functions-*",) + types = tuple("astropy.modeling.math_functions." + m for m in _MODEL_NAMES) def to_yaml_tree_transform(self, model, tag, ctx): return {"func_name": model.func.__name__} diff --git a/asdf_astropy/converters/transform/polynomial.py b/asdf_astropy/converters/transform/polynomial.py index 5c1c1545..baab5ed6 100644 --- a/asdf_astropy/converters/transform/polynomial.py +++ b/asdf_astropy/converters/transform/polynomial.py @@ -16,12 +16,11 @@ class PolynomialConverter(TransformConverterBase): # versions because they don't validate. _DOMAIN_WINDOW_MIN_VERSION = parse_version("1.2.0") - tags = ["tag:stsci.edu:asdf/transform/polynomial-*"] - - types = [ + tags = ("tag:stsci.edu:asdf/transform/polynomial-*",) + types = ( "astropy.modeling.polynomial.Polynomial1D", "astropy.modeling.polynomial.Polynomial2D", - ] + ) def to_yaml_tree_transform(self, model, tag, ctx): from astropy.modeling.polynomial import Polynomial1D, Polynomial2D @@ -95,6 +94,18 @@ def from_yaml_tree_transform(self, node, tag, ctx): return model +_CLASS_NAME_TO_POLY_INFO = { + "Legendre1D": ("legendre", 1), + "Legendre2D": ("legendre", 2), + "Chebyshev1D": ("chebyshev", 1), + "Chebyshev2D": ("chebyshev", 2), + "Hermite1D": ("hermite", 1), + "Hermite2D": ("hermite", 2), +} + +_POLY_INFO_TO_CLASS_NAME = {v: k for k, v in _CLASS_NAME_TO_POLY_INFO.items()} + + class OrthoPolynomialConverter(TransformConverterBase): """ ASDF support for serializing models that inherit @@ -102,30 +113,19 @@ class OrthoPolynomialConverter(TransformConverterBase): """ # Map of model class name to (polynomial type, number of dimensions) tuple: - _CLASS_NAME_TO_POLY_INFO = { - "Legendre1D": ("legendre", 1), - "Legendre2D": ("legendre", 2), - "Chebyshev1D": ("chebyshev", 1), - "Chebyshev2D": ("chebyshev", 2), - "Hermite1D": ("hermite", 1), - "Hermite2D": ("hermite", 2), - } - - _POLY_INFO_TO_CLASS_NAME = {v: k for k, v in _CLASS_NAME_TO_POLY_INFO.items()} - - tags = ["tag:stsci.edu:asdf/transform/ortho_polynomial-*"] - types = [ + tags = ("tag:stsci.edu:asdf/transform/ortho_polynomial-*",) + types = ( "astropy.modeling.polynomial.Legendre1D", "astropy.modeling.polynomial.Legendre2D", "astropy.modeling.polynomial.Chebyshev1D", "astropy.modeling.polynomial.Chebyshev2D", "astropy.modeling.polynomial.Hermite1D", "astropy.modeling.polynomial.Hermite2D", - ] + ) def to_yaml_tree_transform(self, model, tag, ctx): - poly_type = self._CLASS_NAME_TO_POLY_INFO[model.__class__.__name__][0] + poly_type = _CLASS_NAME_TO_POLY_INFO[model.__class__.__name__][0] if model.n_inputs == 1: coefficients = np.array(model.parameters) else: @@ -157,7 +157,7 @@ def from_yaml_tree_transform(self, node, tag, ctx): poly_type = node["polynomial_type"] n_dim = coefficients.ndim - class_name = self._POLY_INFO_TO_CLASS_NAME[(poly_type, n_dim)] + class_name = _POLY_INFO_TO_CLASS_NAME[(poly_type, n_dim)] model_type = getattr(polynomial, class_name) coefficients = np.asarray(node["coefficients"]) diff --git a/asdf_astropy/converters/transform/properties.py b/asdf_astropy/converters/transform/properties.py index 917e711f..5c0d8b64 100644 --- a/asdf_astropy/converters/transform/properties.py +++ b/asdf_astropy/converters/transform/properties.py @@ -3,8 +3,8 @@ class ModelBoundingBoxConverter(Converter): - tags = ["tag:stsci.edu:asdf/transform/property/bounding_box-1.0.0"] - types = ["astropy.modeling.bounding_box.ModelBoundingBox"] + tags = ("tag:stsci.edu:asdf/transform/property/bounding_box-1.0.0",) + types = ("astropy.modeling.bounding_box.ModelBoundingBox",) def to_yaml_tree(self, bbox, tag, ctx): return { @@ -40,8 +40,8 @@ def create_bounding_box(model, cbbox=None): class CompoundBoundingBoxConverter(Converter): - tags = ["tag:stsci.edu:asdf/transform/property/compound_bounding_box-1.0.0"] - types = ["astropy.modeling.bounding_box.CompoundBoundingBox"] + tags = ("tag:stsci.edu:asdf/transform/property/compound_bounding_box-1.0.0",) + types = ("astropy.modeling.bounding_box.CompoundBoundingBox",) def to_yaml_tree(self, cbbox, tag, ctx): node = { diff --git a/asdf_astropy/converters/transform/rotations.py b/asdf_astropy/converters/transform/rotations.py index fc3f07d8..efd9a2fa 100644 --- a/asdf_astropy/converters/transform/rotations.py +++ b/asdf_astropy/converters/transform/rotations.py @@ -7,13 +7,12 @@ class Rotate3DConverter(TransformConverterBase): use the rotate3d tag. """ - tags = ["tag:stsci.edu:asdf/transform/rotate3d-*"] - - types = [ + tags = ("tag:stsci.edu:asdf/transform/rotate3d-*",) + types = ( "astropy.modeling.rotations.RotateNative2Celestial", "astropy.modeling.rotations.RotateCelestial2Native", "astropy.modeling.rotations.EulerAngleRotation", - ] + ) def to_yaml_tree_transform(self, model, tag, ctx): from astropy.modeling import rotations @@ -59,12 +58,11 @@ class RotationSequenceConverter(TransformConverterBase): ASDF support for serializing rotation sequence models. """ - tags = ["tag:stsci.edu:asdf/transform/rotate_sequence_3d-*"] - - types = [ + tags = ("tag:stsci.edu:asdf/transform/rotate_sequence_3d-*",) + types = ( "astropy.modeling.rotations.RotationSequence3D", "astropy.modeling.rotations.SphericalRotationSequence", - ] + ) def to_yaml_tree_transform(self, model, tag, ctx): from astropy.modeling import rotations diff --git a/asdf_astropy/converters/transform/spline.py b/asdf_astropy/converters/transform/spline.py index 09b294cd..0c0b942d 100644 --- a/asdf_astropy/converters/transform/spline.py +++ b/asdf_astropy/converters/transform/spline.py @@ -6,8 +6,8 @@ class SplineConverter(TransformConverterBase): ASDF support for serializing 1D spline models """ - tags = ["tag:stsci.edu:asdf/transform/spline1d-*"] - types = ["astropy.modeling.spline.Spline1D"] + tags = ("tag:stsci.edu:asdf/transform/spline1d-*",) + types = ("astropy.modeling.spline.Spline1D",) def to_yaml_tree_transform(self, model, tag, ctx): return {"knots": model.t, "coefficients": model.c, "degree": model.degree} diff --git a/asdf_astropy/converters/transform/tabular.py b/asdf_astropy/converters/transform/tabular.py index 9900fe2c..7ebf03d5 100644 --- a/asdf_astropy/converters/transform/tabular.py +++ b/asdf_astropy/converters/transform/tabular.py @@ -8,12 +8,11 @@ class TabularConverter(TransformConverterBase): ASDF support for serializing tabular models. """ - tags = ["tag:stsci.edu:asdf/transform/tabular-*"] - - types = [ + tags = ("tag:stsci.edu:asdf/transform/tabular-*",) + types = ( "astropy.modeling.tabular.Tabular1D", "astropy.modeling.tabular.Tabular2D", - ] + ) def to_yaml_tree_transform(self, model, tag, ctx): node = {} diff --git a/asdf_astropy/converters/unit/equivalency.py b/asdf_astropy/converters/unit/equivalency.py index 82c0d3a5..67e273c3 100644 --- a/asdf_astropy/converters/unit/equivalency.py +++ b/asdf_astropy/converters/unit/equivalency.py @@ -2,9 +2,8 @@ class EquivalencyConverter(Converter): - tags = ["tag:astropy.org:astropy/units/equivalency-*"] - - types = ["astropy.units.equivalencies.Equivalency"] + tags = ("tag:astropy.org:astropy/units/equivalency-*",) + types = ("astropy.units.equivalencies.Equivalency",) def to_yaml_tree(self, obj, tag, ctx): return [ diff --git a/asdf_astropy/converters/unit/magunit.py b/asdf_astropy/converters/unit/magunit.py index eb7d3adc..e73cdffc 100644 --- a/asdf_astropy/converters/unit/magunit.py +++ b/asdf_astropy/converters/unit/magunit.py @@ -2,11 +2,8 @@ class MagUnitConverter(Converter): - tags = ["tag:astropy.org:astropy/units/magunit-*"] - - types = [ - "astropy.units.function.logarithmic.MagUnit", - ] + tags = ("tag:astropy.org:astropy/units/magunit-*",) + types = ("astropy.units.function.logarithmic.MagUnit",) def to_yaml_tree(self, obj, tag, ctx): return {"unit": obj.physical_unit} diff --git a/asdf_astropy/converters/unit/quantity.py b/asdf_astropy/converters/unit/quantity.py index 1f2bf590..aabe25dd 100644 --- a/asdf_astropy/converters/unit/quantity.py +++ b/asdf_astropy/converters/unit/quantity.py @@ -3,14 +3,13 @@ class QuantityConverter(Converter): - tags = ["tag:stsci.edu:asdf/unit/quantity-*"] - - types = [ + tags = ("tag:stsci.edu:asdf/unit/quantity-*",) + types = ( "astropy.units.quantity.Quantity", # The Distance class has no tag of its own, so we # just serialize it as a quantity. "astropy.coordinates.distances.Distance", - ] + ) def to_yaml_tree(self, obj, tag, ctx): node = { diff --git a/asdf_astropy/converters/unit/unit.py b/asdf_astropy/converters/unit/unit.py index aae36ebc..9b8ced74 100644 --- a/asdf_astropy/converters/unit/unit.py +++ b/asdf_astropy/converters/unit/unit.py @@ -4,12 +4,11 @@ class UnitConverter(Converter): - tags = [ + tags = ( "tag:stsci.edu:asdf/unit/unit-*", "tag:astropy.org:astropy/units/unit-*", - ] - - types = [ + ) + types = ( "astropy.units.core.CompositeUnit", "astropy.units.core.IrreducibleUnit", "astropy.units.core.NamedUnit", @@ -19,7 +18,7 @@ class UnitConverter(Converter): "astropy.units.core.UnrecognizedUnit", "astropy.units.function.mixin.IrreducibleFunctionUnit", "astropy.units.function.mixin.RegularFunctionUnit", - ] + ) def select_tag(self, obj, tags, ctx): from astropy.units import UnitsError, UnitsWarning From 3a6b5d39690113e77ccfa36e1ccb22212ef847e2 Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Thu, 13 Jul 2023 12:39:31 -0400 Subject: [PATCH 2/4] Have magunit use sets instead of lists --- asdf_astropy/converters/unit/tests/test_magunit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asdf_astropy/converters/unit/tests/test_magunit.py b/asdf_astropy/converters/unit/tests/test_magunit.py index 28ccd504..4b633e39 100644 --- a/asdf_astropy/converters/unit/tests/test_magunit.py +++ b/asdf_astropy/converters/unit/tests/test_magunit.py @@ -4,7 +4,7 @@ def create_builtin_units(): - return [u for u in list(units.__dict__.values()) if isinstance(u, units.MagUnit)] + return {u for u in list(units.__dict__.values()) if isinstance(u, units.MagUnit)} @pytest.mark.parametrize("unit", create_builtin_units()) @@ -34,7 +34,7 @@ def create_magunits(): else: magunits.append(magunit) - return magunits + return set(magunits) @pytest.mark.parametrize("unit", create_magunits()) From 43f5cb534a25711b2088988046ba1a99aa33f88b Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Thu, 13 Jul 2023 16:56:50 -0400 Subject: [PATCH 3/4] Update changes --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 8b9a55a9..1ef29679 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,7 @@ - Drop support for Python 3.8 in accordance with NEP 29. [#180] - Update ``RepresentationConverter`` for new class paths in astropy [#181] +- Update Converters so that all Class Variables are immutable [#188] 0.4.0 (2023-03-20) ------------------ From 9f723f31dce56fc213ddcbfb9e13854eb7a92c6c Mon Sep 17 00:00:00 2001 From: William Jamieson Date: Fri, 14 Jul 2023 10:26:34 -0400 Subject: [PATCH 4/4] Update asdf_astropy/converters/unit/tests/test_magunit.py --- asdf_astropy/converters/unit/tests/test_magunit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asdf_astropy/converters/unit/tests/test_magunit.py b/asdf_astropy/converters/unit/tests/test_magunit.py index 4b633e39..d8d6bb2e 100644 --- a/asdf_astropy/converters/unit/tests/test_magunit.py +++ b/asdf_astropy/converters/unit/tests/test_magunit.py @@ -34,7 +34,7 @@ def create_magunits(): else: magunits.append(magunit) - return set(magunits) + return frozenset(magunits) @pytest.mark.parametrize("unit", create_magunits())