I've got it - the offending code was, in the end, these lines:
class SkyQuery(object):
_unique_fields = ["parameter",
"ensemble",
"forecast",
"station"]
_field_tag_values = [field + "_value" for field in _unique_fields]
Naming the temporary variable "field" in my list comprehension was causing the problem. Python was retaining it after I was done. This behavior is consistent, I just wasn't expecting it.
I see three solutions here (the third was suggested by user4815162342). I implemented the third.
Rename the temporary variable to
x
rather thanfield
. Then I still havex
as a temporary variable floating around in my code, but because no members should be calledx
it doesn't bother me.Call
del(field)
to delete the field. I don't like callingdel()
and I thought it would clutter up my code, but it would work if I really needed to be able to access that variable later on.replace the list comprehension with a generator expression
list(field + "_value" for field in _unique_fields)
which does not share this problem