Fix crashes related to use of weakrefs on :data:`typing.TypeVar`.