Skip to content
Open
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
8 changes: 8 additions & 0 deletions astropy/coordinates/sky_coordinate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import inspect
import operator
import re
import warnings
Expand Down Expand Up @@ -871,6 +872,13 @@ 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.
"""
try:
inspect.getattr_static(self, attr)
except AttributeError:
pass
else:
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
32 changes: 32 additions & 0 deletions astropy/coordinates/tests/test_sky_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -2165,3 +2165,35 @@ def test_match_to_catalog_3d_and_sky():
npt.assert_array_equal(idx, [0, 1, 2, 3])
assert_allclose(angle, 0 * u.deg, atol=1e-14 * u.deg, rtol=0)
assert_allclose(distance, 0 * u.kpc, atol=1e-14 * u.kpc, rtol=0)


def test_subclass_property_attribute_error_propagates():
class CustomSkyCoord(SkyCoord):
@property
def prop(self):
return self.random_attr

coord = CustomSkyCoord(RA, DEC, frame="icrs")

with pytest.raises(AttributeError) as excinfo:
coord.prop

message = str(excinfo.value)
assert "random_attr" in message
assert "prop" not in message


def test_transform_alias_access_unchanged():
coord = SkyCoord(RA, DEC, frame="galactic")

transformed = coord.icrs

assert isinstance(transformed, SkyCoord)
assert transformed.frame.name == "icrs"


def test_frame_attribute_delegation_unchanged():
obstime = Time("J2010")
coord = SkyCoord(RA, DEC, frame="fk5", obstime=obstime)

assert coord.obstime is obstime