[Python-Dev] pathlib - current status of discussions (original) (raw)
Brett Cannon brett at python.org
Wed Apr 13 16:42:48 EDT 2016
- Previous message (by thread): [Python-Dev] pathlib - current status of discussions
- Next message (by thread): [Python-Dev] pathlib - current status of discussions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, 13 Apr 2016 at 13:40 Chris Barker <chris.barker at noaa.gov> wrote:
so are we worried that fspath will exist and be callable, but might raise an AttributeError somewhere inside itself? if so isn't it broken anyway, so should it be ignored?
It should propagate instead of swallowing up the exception, otherwise it's hard to debug why fspath seems to be ignored.
and I know it's asking permission rather than forgiveness, but what's wrong with: if hasattr(path, "fspath"): path = path.fspath() if you really want to check for the existence of the attribute first? Nothing.
or even:
path = path.fspath if hasattr(path, "fspath") else path That also works.
(OK, really a Pythonic style question now....)
Yes, this is getting a bit side-tracked over some example code to just get a concept across.
-Brett
-CHB
On Wed, Apr 13, 2016 at 12:54 PM, Brett Cannon <brett at python.org> wrote:
On Wed, 13 Apr 2016 at 12:39 Fred Drake <fred at fdrake.net> wrote: On Wed, Apr 13, 2016 at 3:24 PM, Chris Angelico <rosuav at gmail.com> wrote: > Is that the intention, or should the exception catching be narrower? I > know it's clunky to write it in Python, but AIUI it's less so in C: > > try: > callme = path.fspath > except AttributeError: > pass > else: > path = callme() +1 for this variant; I really don't like masking errors inside the fspath implementation. Don't read too much into the code in that gist. I just did them quickly to get the point across of the proposals in terms of str/bytes, not what will be proposed in any final patch.
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/chris.barker%40noaa.gov
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160413/e66f2ecb/attachment.html>
- Previous message (by thread): [Python-Dev] pathlib - current status of discussions
- Next message (by thread): [Python-Dev] pathlib - current status of discussions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]