Skip to content

Commit 2112c12

Browse files
committed
This fixes one of the slicing-related tests that was failing on Python 2. There is still a separate bug that seems to affect both Python versions, but this fixes the case that was currently in the test suite.
1 parent c5452e6 commit 2112c12

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎astropy/modeling/core.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,14 @@ def __getitem__(cls, index):
14571457
return cls._get_slice(index.start, index.stop)
14581458

14591459
def __getattr__(cls, attr):
1460-
if attr in cls.param_names:
1460+
# Ensuring the param_names has actually be initialized is important,
1461+
# otherwise this can cause premature setup of param_names before class
1462+
# construction is complete. Specifically, on Python 2, if the
1463+
# hasattr() check for __qualname__ fails we'll end up in this
1464+
# __getattr__, but since the cls._slice_offset attribute may not have
1465+
# been properly set yet, the generated param_names will be incorrect.
1466+
# This is admittedly brittle and indicates an area for restructuring
1467+
if cls._param_names is not None and attr in cls.param_names:
14611468
cls._init_param_descriptors()
14621469
return getattr(cls, attr)
14631470

0 commit comments

Comments
 (0)