yaml / pyyaml

Canonical source repository for PyYAML
MIT License
2.47k stars 507 forks source link

Clarify that load_all methods return a generator, not a sequence #762

Closed mpitt closed 8 months ago

mpitt commented 8 months ago

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.

mpitt commented 8 months ago

Mhm I realised that it should probably be a bug against https://github.com/yaml/pyyaml.org, I will move it there