Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions astropy/coordinates/sky_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,10 +867,12 @@ def _is_name(self, string):
)

def __getattr__(self, attr):
"""
Overrides getattr to return coordinates that this can be transformed
to, based on the alias attr in the primary transform graph.
"""
# If this attribute exists on the class (e.g., a subclass property),
# try to access it via normal attribute lookup so that any
# AttributeError raised by the descriptor propagates unchanged.
for cls in type(self).mro():
if attr in getattr(cls, "__dict__", {}):
return object.__getattribute__(self, attr)
if "_sky_coord_frame" in self.__dict__:
if self._is_name(attr):
return self # Should this be a deepcopy of self?
Expand Down Expand Up @@ -2220,4 +2222,4 @@ def from_name(cls, name, frame="icrs", parse=False, cache=True):
if frame in ("icrs", icrs_coord.__class__):
return icrs_sky_coord
else:
return icrs_sky_coord.transform_to(frame)
return icrs_sky_coord.transform_to(frame)
19 changes: 19 additions & 0 deletions astropy/coordinates/tests/test_sky_coord_subclass_attr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import pytest
import astropy.units as u
from astropy.coordinates import SkyCoord

class CustomCoord(SkyCoord):
@property
def prop(self):
# Access a non-existent attribute to trigger AttributeError from the descriptor
return self.random_attr


def test_subclass_property_inner_attributeerror_message():
c = CustomCoord('00h42m30s', '+41d12m00s', frame='icrs')
with pytest.raises(AttributeError) as excinfo:
_ = c.prop
# Ensure the error message mentions the missing inner attribute, not the property name
assert "random_attr" in str(excinfo.value)
assert "prop" not in str(excinfo.value)