GateNLP/python-gatenlp

All DocumentSource and DocumentDestination classes should be context managers

johann-petrak opened this issue · 0 comments

The proper way to use any source or destination should be as context managers:

with SomeDocSource as src:
    for doc in src:
        dosomething(doc)

with SomeDocDest as dest:
    for doc in mydocs:
        dest.append(doc)

This should be the standard usage pattern even if the source or destination does not need to get opened/closed.

If opening and closing is necessary, the convention is that opening is done when the instance is created and the close() method is called when the context manager exits. This allows to still use the classes without with