Skip to content

Conversation

@sneakers-the-rat
Copy link

The linkml-runtime tests print many ominous warnings like:

linkml_runtime/loaders/delimited_file_loader.py:62: ResourceWarning: unclosed file <_io.TextIOWrapper name='linkml-runtime/tests/test_loaders_dumpers/output/books_flattened_02.tsv' mode='r' encoding='UTF-8'>
  objs = unflatten_from_csv(input, config=config, **kwargs)
ResourceWarning: Enable tracemalloc to get the object allocation traceback

This is because a file object is opened without ever being closed.

Not closing files is safer when reading from them than when writing to them, but it still keeps files locked, uses additional file handles, and can still corrupt files in rare cases on crashes.

this PR splits the function in two and uses a context manager when the thing passed to us is a string. It still allows someone to pass an open file handle to the function, but otherwise raises a ValueError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant