Skip to content

Commit 7cf99bb

Browse files
committed
[astropy#11094] Remove use of OrderedDescriptor[Container] from
astropy.coordinates Now frame_attributes is simply set in FrameMeta.__new__, and Attribute uses __set_name__. A bit of other minor simplification in FrameMeta.__new__
1 parent 6c82565 commit 7cf99bb

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎astropy/coordinates/attributes.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
# Project
99
from astropy import units as u
10-
from astropy.utils import OrderedDescriptor, ShapedLikeNDArray
10+
from astropy.utils import ShapedLikeNDArray
1111

1212
__all__ = ['Attribute', 'TimeAttribute', 'QuantityAttribute',
1313
'EarthLocationAttribute', 'CoordinateAttribute',
1414
'CartesianRepresentationAttribute',
1515
'DifferentialAttribute']
1616

1717

18-
class Attribute(OrderedDescriptor):
18+
class Attribute:
1919
"""A non-mutable data descriptor to hold a frame attribute.
2020
2121
This class must be used to define frame attributes (e.g. ``equinox`` or
@@ -50,15 +50,16 @@ class FK4(BaseCoordinateFrame):
5050
``default is None`` and no value was supplied during initialization.
5151
"""
5252

53-
_class_attribute_ = 'frame_attributes'
54-
_name_attribute_ = 'name'
5553
name = '<unbound>'
5654

5755
def __init__(self, default=None, secondary_attribute=''):
5856
self.default = default
5957
self.secondary_attribute = secondary_attribute
6058
super().__init__()
6159

60+
def __set_name__(self, owner, name):
61+
self.name = name
62+
6263
def convert_input(self, value):
6364
"""
6465
Validate the input ``value`` and convert to expected attribute class.

‎astropy/coordinates/baseframe.py‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
from astropy.utils.decorators import lazyproperty, format_doc
2222
from astropy.utils.exceptions import AstropyWarning, AstropyDeprecationWarning
2323
from astropy import units as u
24-
from astropy.utils import (OrderedDescriptorContainer, ShapedLikeNDArray,
25-
check_broadcast)
24+
from astropy.utils import ShapedLikeNDArray, check_broadcast
2625
from .transformations import TransformGraph
2726
from . import representation as r
2827
from .angles import Angle
@@ -197,13 +196,12 @@ def __new__(cls, reprname, framename, defaultunit='recommended'):
197196
# TODO: This is only needed so that BaseCoordinateFrame can have
198197
# OrderedDescriptorContainer as a metaclass. Trying to use
199198
# metaclass=OrderedDescriptorContainer directly causes a metaclass conflict.
200-
class FrameMeta(OrderedDescriptorContainer, abc.ABCMeta):
199+
class FrameMeta(abc.ABCMeta):
201200
pass
202201

203202

204203
@format_doc(base_doc, components=_components, footer="")
205-
class BaseCoordinateFrame(ShapedLikeNDArray,
206-
metaclass=FrameMeta):
204+
class BaseCoordinateFrame(ShapedLikeNDArray):
207205
"""
208206
The base class for coordinate frames.
209207
@@ -251,8 +249,6 @@ class BaseCoordinateFrame(ShapedLikeNDArray,
251249
# attributes.
252250
frame_specific_representation_info = {}
253251

254-
_inherit_descriptors_ = (Attribute,)
255-
256252
frame_attributes = {}
257253
# Default empty frame_attributes dict
258254

@@ -262,6 +258,7 @@ def __init_subclass__(cls, **kwargs):
262258
default_repr = getattr(cls, 'default_representation', None)
263259
default_diff = getattr(cls, 'default_differential', None)
264260
repr_info = getattr(cls, 'frame_specific_representation_info', None)
261+
frame_attrs = getattr(cls, 'frame_attributes', None)
265262

266263
# Then, to make sure this works for subclasses-of-subclasses, we also
267264
# have to check for cases where the attribute names have already been
@@ -286,6 +283,19 @@ def __init_subclass__(cls, **kwargs):
286283
cls._create_readonly_property('frame_specific_representation_info',
287284
copy.deepcopy(repr_info))
288285

286+
# Set the frame attributes
287+
# TODO: Should this be made to use readonly_prop_factory as well or
288+
# would it be inconvenient for getting the frame_attributes from
289+
# classes?
290+
if frame_attrs is None:
291+
frame_attrs = {}
292+
else:
293+
frame_attrs = frame_attrs.copy()
294+
295+
frame_attrs.update({k: v for k, v in cls.__dict__.items()
296+
if isinstance(v, Attribute)})
297+
cls.frame_attributes = frame_attrs
298+
289299
# Deal with setting the name of the frame:
290300
if not hasattr(cls, 'name'):
291301
cls.name = cls.__name__.lower()

0 commit comments

Comments
 (0)