This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jaraco
Recipients FFY00, brett.cannon, docs@python, jaraco
Date 2021-05-23.17:18:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1621790327.04.0.971259425233.issue44196@roundup.psfhosted.org>
In-reply-to
Content
Having a look at the `open` function (https://docs.python.org/3/library/functions.html#open), it does not define which exceptions might be thrown. Similarly for pathlib.Path.open (https://docs.python.org/3/library/pathlib.html#pathlib.Path.open) and zipfile.Path.open (https://docs.python.org/3/library/zipfile.html#zipfile.Path.open).

And since the canonical implementation of a Traversable resource is those two Path classes, it seems infeasible for the protocol to enforce a specific constraint on the available exceptions.

I think the best this protocol can do is advertise that the underlying implementation may raise an Exception if the target indicated by self cannot be opened (allowing for an Exception where appropriate), but in my opinion, that's the default interface for any protocol (or function) unless otherwise specified.

I don't want to explicitly call out FileNotFoundError or IsADirectoryError because those exceptions happen to be the most common. Consider for example the case where permission is not granted for read:

```
$ pathlib.Path('./foo').open()
PermissionError: [Errno 13] Permission denied: 'foo'
```

That's yet another case where Traversable.open might raise something other than FileNotFoundError.

In my opinion, unless the Traversable objects are expected to handle or transform exceptions, it's fine to simply delegate to the underlying implementations and allow any exceptions to bubble through.
History
Date User Action Args
2021-05-23 17:18:47jaracosetrecipients: + jaraco, brett.cannon, docs@python, FFY00
2021-05-23 17:18:47jaracosetmessageid: <1621790327.04.0.971259425233.issue44196@roundup.psfhosted.org>
2021-05-23 17:18:47jaracolinkissue44196 messages
2021-05-23 17:18:46jaracocreate