pyyaml.org icon indicating copy to clipboard operation
pyyaml.org copied to clipboard

Clarify that load_all methods return a generator, not a sequence

Open mpitt opened this issue 2 years ago • 0 comments

The documentation for load_all and safe_load_all states (emphasis mine):

... returns a sequence of Python objects ...

In reality, those methods return a generator, which is not the same thing as a sequence. For example:

with open(filename) as f:
    docs = yaml.safe_load_all(f)
for d in docs:
    # do stuff

will raise ValueError: I/O operation on closed file. which if docs was really a sequence doesn't make sense.

(Moved from https://github.com/yaml/pyyaml/issues/762)

mpitt avatar Nov 08 '23 13:11 mpitt