Do not assume hasattr is available in Metric.__del__
Python does not guarantee that builtins are available by the time __del__ is called, so using hasattr is unsafe. PiperOrigin-RevId: 254255638
This commit is contained in:
parent
3e3b915613
commit
7b1ebf50c9
@ -121,10 +121,14 @@ class Metric(object):
|
||||
self._metric = self._metric_methods[self._label_length].create(*args)
|
||||
|
||||
def __del__(self):
|
||||
if hasattr(self, '_metric'):
|
||||
try:
|
||||
deleter = self._metric_methods[self._label_length].delete
|
||||
metric = self._metric
|
||||
except AttributeError:
|
||||
return
|
||||
|
||||
if deleter is not None:
|
||||
deleter(self._metric)
|
||||
deleter(metric)
|
||||
|
||||
def get_cell(self, *labels):
|
||||
"""Retrieves the cell."""
|
||||
|
Loading…
Reference in New Issue
Block a user