forked from astropy/astropy
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
User request
Subclassed SkyCoord gives misleading attribute access message. When a subclass property attempts to access a non-existent attribute, the error message claims the property itself does not exist instead of pointing to the missing inner attribute.
Reproducer:
import astropy.coordinates as coord
class custom_coord(coord.SkyCoord):
@property
def prop(self):
return self.random_attr
c = custom_coord('00h42m30s', '+41d12m00s', frame='icrs')
c.propObserved error (example):
AttributeError: 'custom_coord' object has no attribute 'prop'
Researcher specification
Summary:
- SkyCoord.getattr currently raises a standardized AttributeError for unknown attributes. When a subclass-defined descriptor/property exists but its getter raises AttributeError, Python falls back to getattr, which then masks the original exception and reports the property name as missing.
Fix:
- In SkyCoord.getattr, first perform a static attribute existence check using inspect.getattr_static(self, attr). If the attribute exists on the class/object (descriptor/property/method), delegate to object.getattribute(self, attr) so any AttributeError from the getter is propagated unchanged. Otherwise, proceed with the existing SkyCoord dynamic behavior (frame aliases, frame attributes, underlying frame delegation, and standardized AttributeError for truly missing attributes).
Tests:
- Add tests under astropy/coordinates/tests/ that:
- Verify that a SkyCoord subclass property whose getter accesses a missing attribute raises an AttributeError mentioning the missing inner attribute (e.g., 'random_attr'), not the property name ('prop').
- Confirm transform alias access (e.g., c.icrs) remains unaffected.
- Confirm frame attribute delegation (e.g., c.obstime) remains unaffected.
Compatibility:
- No API changes; fix narrows behavior to preserve the original exceptions from subclass-defined descriptors.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels