|
21 | 21 | from astropy.utils.decorators import lazyproperty, format_doc |
22 | 22 | from astropy.utils.exceptions import AstropyWarning, AstropyDeprecationWarning |
23 | 23 | from astropy import units as u |
24 | | -from astropy.utils import (OrderedDescriptorContainer, ShapedLikeNDArray, |
25 | | - check_broadcast) |
| 24 | +from astropy.utils import ShapedLikeNDArray, check_broadcast |
26 | 25 | from .transformations import TransformGraph |
27 | 26 | from . import representation as r |
28 | 27 | from .angles import Angle |
@@ -141,51 +140,36 @@ def _normalize_representation_type(kwargs): |
141 | 140 | # with ShapedLikeNDArray below (which is an ABC); without it, one gets |
142 | 141 | # "TypeError: metaclass conflict: the metaclass of a derived class must be a |
143 | 142 | # (non-strict) subclass of the metaclasses of all its bases" |
144 | | -class FrameMeta(OrderedDescriptorContainer, abc.ABCMeta): |
| 143 | +class FrameMeta(abc.ABCMeta): |
145 | 144 | def __new__(mcls, name, bases, members): |
146 | | - if 'default_representation' in members: |
147 | | - default_repr = members.pop('default_representation') |
148 | | - found_default_repr = True |
149 | | - else: |
150 | | - default_repr = None |
151 | | - found_default_repr = False |
152 | | - |
153 | | - if 'default_differential' in members: |
154 | | - default_diff = members.pop('default_differential') |
155 | | - found_default_diff = True |
156 | | - else: |
157 | | - default_diff = None |
158 | | - found_default_diff = False |
159 | | - |
160 | | - if 'frame_specific_representation_info' in members: |
161 | | - repr_info = members.pop('frame_specific_representation_info') |
162 | | - found_repr_info = True |
163 | | - else: |
164 | | - repr_info = None |
165 | | - found_repr_info = False |
| 145 | + missing = object() |
| 146 | + default_repr = members.pop('default_representation', missing) |
| 147 | + default_diff = members.pop('default_differential', missing) |
| 148 | + repr_info = members.pop('frame_specific_representation_info', missing) |
| 149 | + frame_attrs = members.pop('frame_attributes', missing) |
166 | 150 |
|
167 | 151 | # somewhat hacky, but this is the best way to get the MRO according to |
168 | 152 | # https://mail.python.org/pipermail/python-list/2002-December/167861.html |
169 | 153 | tmp_cls = super().__new__(mcls, name, bases, members) |
170 | 154 |
|
171 | | - # now look through the whole MRO for the class attributes, raw for |
172 | | - # frame_attr_names, and leading underscore for others |
| 155 | + # now look through the whole MRO for the class attributes |
173 | 156 | for m in (c.__dict__ for c in tmp_cls.__mro__): |
174 | | - if not found_default_repr and '_default_representation' in m: |
| 157 | + if default_repr is missing and '_default_representation' in m: |
175 | 158 | default_repr = m['_default_representation'] |
176 | | - found_default_repr = True |
177 | 159 |
|
178 | | - if not found_default_diff and '_default_differential' in m: |
| 160 | + if default_diff is missing and '_default_differential' in m: |
179 | 161 | default_diff = m['_default_differential'] |
180 | | - found_default_diff = True |
181 | 162 |
|
182 | | - if (not found_repr_info |
| 163 | + if (repr_info is missing |
183 | 164 | and '_frame_specific_representation_info' in m): |
184 | 165 | # create a copy of the dict so we don't mess with the contents |
185 | 166 | repr_info = m['_frame_specific_representation_info'].copy() |
186 | | - found_repr_info = True |
187 | 167 |
|
188 | | - if found_default_repr and found_default_diff and found_repr_info: |
| 168 | + if frame_attrs is missing and 'frame_attributes' in m: |
| 169 | + frame_attrs = m['frame_attributes'].copy() |
| 170 | + |
| 171 | + if missing not in (default_repr, default_diff, repr_info, |
| 172 | + frame_attrs): |
189 | 173 | break |
190 | 174 | else: |
191 | 175 | raise ValueError( |
@@ -279,6 +263,14 @@ def __new__(mcls, name, bases, members): |
279 | 263 | 'frame_specific_representation_info', |
280 | 264 | copy.deepcopy(repr_info)) |
281 | 265 |
|
| 266 | + # Set the frame attributes |
| 267 | + # TODO: Should this be made to use readonly_prop_factory as well or |
| 268 | + # would it be inconvenient for getting the frame_attributes from |
| 269 | + # classes? |
| 270 | + frame_attrs.update({k: v for k, v in members.items() |
| 271 | + if isinstance(v, Attribute)}) |
| 272 | + members['frame_attributes'] = frame_attrs |
| 273 | + |
282 | 274 | # now set the frame name as lower-case class name, if it isn't explicit |
283 | 275 | if 'name' not in members: |
284 | 276 | members['name'] = name.lower() |
@@ -407,8 +399,6 @@ class BaseCoordinateFrame(ShapedLikeNDArray, metaclass=FrameMeta): |
407 | 399 | # attributes. |
408 | 400 | frame_specific_representation_info = {} |
409 | 401 |
|
410 | | - _inherit_descriptors_ = (Attribute,) |
411 | | - |
412 | 402 | frame_attributes = {} |
413 | 403 | # Default empty frame_attributes dict |
414 | 404 |
|
|
0 commit comments