ScanContext#

class ScanContext(generator, cleanup_func)#

Bases: AbstractContextManager[Iterator[T]], Generator[T, None, None], Generic[T]

Context manager wrapper for scan operations that ensures proper cleanup.

Implements two use cases:

  • Recommended: ContextManager over Iterator[T] for use with ‘with’ statements

  • Legacy: Generator[T] for direct iteration (issues deprecation warning)

When used without entering the context manager, a deprecation warning is issued.

Note

This is a generic class parameterized by type T, which represents the type of items yielded by the generator.

Methods Summary

close()

Close the generator and perform cleanup.

send(value)

Send a value to the generator (required by Generator protocol).

throw(typ[, val, tb])

Throw an exception into the generator (required by Generator protocol).

Methods Documentation

close()#

Close the generator and perform cleanup.

Return type:

None

send(value)#

Send a value to the generator (required by Generator protocol).

Return type:

TypeVar(T)

throw(typ, val=None, tb=None)#

Throw an exception into the generator (required by Generator protocol).

Return type:

TypeVar(T)