homepage

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 Tyler.Crompton
Recipients Arfrever, Tyler.Crompton, ethan.furman, ncoghlan
Date 2012年06月28日.14:43:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1340894637.46.0.0674161925355.issue15209@psf.upfronthosting.co.za>
In-reply-to
Content
I'm in a little over my head as I can't conceptualize __cause__, so I may be looking over things.
First, you, Ethan, said the following:
>It's also not difficult to work around if you really want to toss the extra info:
>
> except NameError:
> try:
> fallback_module.getch()
> except Exception as exc:
> raise exc from None
>
>A total of three more words to get the desired behavior (and small ones at that).
Counter-argument: if it's just three words, then why was the shorthand without the from clause implemented in the first place?
My use case was primarily based on the idea that the unavailability of the windows module (from the example) is irrelevant information to, say, Unix users. When an exception is raised, the user shouldn't have to see any Windows-related exceptions (that is if there is an alternate solution).
One could fix this with a little bit of refactoring, though:
 import sys as _sys
 def getch(prompt=''):
 '''Get and return a character (similar to `input()`).'''
 print(prompt, end='')
 if 'windows_module' in _sys.modules:
 return windows_module.getch()
 else:
 try:
 return fallback_module.getch()
 except Exception:
 raise from None
But it's EAFP. Heck, one could even do the following:
 def getch(prompt=''):
 '''Get and return a character (similar to `input()`).'''
 print(prompt, end='')
 try:
 return windows_module.getch()
 except NameError:
 pass
 try:
 return fallback_module.getch()
 except Exception:
 raise
But that's not really ideal. I've played around with the traceback module a little and (very) briefly played with the exceptions themselves. Is there not an easier way to suppress a portion of an exception? Like I said, such information is irrelevant to non-Windows users.
History
Date User Action Args
2012年06月28日 14:43:57Tyler.Cromptonsetrecipients: + Tyler.Crompton, ncoghlan, Arfrever, ethan.furman
2012年06月28日 14:43:57Tyler.Cromptonsetmessageid: <1340894637.46.0.0674161925355.issue15209@psf.upfronthosting.co.za>
2012年06月28日 14:43:56Tyler.Cromptonlinkissue15209 messages
2012年06月28日 14:43:55Tyler.Cromptoncreate

AltStyle によって変換されたページ (->オリジナル) /