Am 22.04.21 um 10:42 schrieb Chris Angelico:
File-like objects are used VERY frequently in the stdlib, and actual
open file objects have quite a large interface. The use-case is a
pretty real one: "if I were to create a simulant file object to pass
to json.load(), what methods do I need?".
Maybe in some cases, the "smaller protocols" option is practical, but
it would need to have a useful name. For instance, if it needs to be
readable, iterable, closeable, and autocloseable via
__enter__/__exit__, that's ... uhh.... a readable, iterable, closeable
context manager? Not an improvement over "file-like object".
Experience from typeshed shows that many functions in the stdlib and
third-party libraries only use one or very few methods, very often just
read() or write(). From a practical standpoint, small protocols seem
quite feasible. These are quite an improvement over "file-like" objects,
where no one knows what that actually means.
- Sebastian
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/H33OH6GGIGHR7SVE6NL32I7OBO7B7F7E/
Code of Conduct: http://python.org/psf/codeofconduct/