Skip to content

Commit f112b35

Browse files
committed
Change weakref _parent_ref to direct ref _parent.
This introduces a reference cycle, but should be OK. Unlike e.g. Table and Column, there is very little risk of wanting an info object without the parent data object.
1 parent a1f8e4a commit f112b35

4 files changed

Lines changed: 10 additions & 12 deletions

File tree

‎astropy/coordinates/sky_coordinate.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def unit(self):
6666

6767
@property
6868
def _repr_data(self):
69-
if self._parent_ref is None:
69+
if self._parent is None:
7070
return None
7171

72-
sc = self._parent_ref()
72+
sc = self._parent
7373
if (issubclass(sc.representation, SphericalRepresentation) and
7474
isinstance(sc.data, UnitSphericalRepresentation)):
7575
repr_data = sc.represent_as(sc.data.__class__, in_frame_units=True)

‎astropy/io/ascii/html.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,13 @@ def write(self, table):
360360
w.data(col.info.name.strip())
361361
w.end(indent=False)
362362
col_str_iters = []
363-
new_cols = []
364363
for col in cols:
365364
if len(col.shape) > 1 and self.html['multicol']:
366365
span = col.shape[1]
367366
for i in range(span):
368367
# Split up multicolumns into separate columns
369368
new_col = Column([el[i] for el in col])
370369
col_str_iters.append(new_col.info.iter_str_vals())
371-
new_cols.append(new_col)
372370
else:
373371
col_str_iters.append(col.info.iter_str_vals())
374372

‎astropy/table/info.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ def table_info(tbl, option='attributes', out=''):
115115
out.writelines(outline + os.linesep for outline in outlines)
116116

117117
class TableInfo(object):
118-
_parent_ref = None
118+
_parent = None
119119

120120
def __call__(self, option='attributes', out=''):
121-
return table_info(self._parent_ref(), option, out)
121+
return table_info(self._parent, option, out)
122122

123123
__call__.__doc__ = table_info.__doc__
124124

‎astropy/utils/data_info.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __init__(self, info_cls):
155155
def __get__(self, instance, owner_cls):
156156
if 'info' not in instance.__dict__:
157157
instance.__dict__['info'] = self.info_cls()
158-
instance.__dict__['info']._parent_ref = weakref.ref(instance)
158+
instance.__dict__['info']._parent = instance
159159
return instance.__dict__['info']
160160

161161
def __set__(self, instance, value):
@@ -175,7 +175,7 @@ class DataInfo(object):
175175
attr_names = set(['name', 'unit', 'dtype', 'format', 'description', 'meta'])
176176
_attrs_no_copy = set()
177177
_info_summary_attrs = ('dtype', 'shape', 'unit', 'format', 'description', 'class')
178-
_parent_ref = None
178+
_parent = None
179179

180180
def __init__(self):
181181
self._attrs = dict((attr, None) for attr in self.attr_names)
@@ -191,7 +191,7 @@ def __getattr__(self, attr):
191191
return super(DataInfo, self).__getattribute__(attr)
192192

193193
if attr in self.attrs_from_parent:
194-
return getattr(self._parent_ref(), attr)
194+
return getattr(self._parent, attr)
195195

196196
try:
197197
value = self._attrs[attr]
@@ -215,7 +215,7 @@ def __setattr__(self, attr, value):
215215
# class property (getter/setter) for this attribute then set
216216
# attribute directly in parent.
217217
if attr in self.attrs_from_parent and not isinstance(propobj, property):
218-
setattr(self._parent_ref(), attr, value)
218+
setattr(self._parent, attr, value)
219219
return
220220

221221
# Check if there is a property setter and use it if possible.
@@ -307,7 +307,7 @@ class = Column
307307
if out == '':
308308
out = sys.stdout
309309

310-
dat = self._parent_ref()
310+
dat = self._parent
311311
info = OrderedDict()
312312
name = dat.info.name
313313
if name is not None:
@@ -363,7 +363,7 @@ def iter_str_vals(self):
363363
This is a mixin-safe version of Column.iter_str_vals.
364364
"""
365365
from ..table.column import FORMATTER
366-
col = self._parent_ref()
366+
col = self._parent
367367
parent_table = self.parent_table
368368
formatter = FORMATTER if parent_table is None else parent_table.formatter
369369
_pformat_col_iter = formatter._pformat_col_iter

0 commit comments

Comments
 (0)