[Python-Dev] PEP 414 updated
Vinay Sajip
vinay_sajip at yahoo.co.uk
Sun Mar 4 14:14:18 CET 2012
Zbigniew Jędrzejewski-Szmek <zbyszek <at> in.waw.pl> writes:
> if sys.version_info[0] < 3:
> raise NotImplementedError('This hook is implemented for Python 3 only')
>
> Wouldn't it be better if the hook did nothing when on python 2?
> I think it'll make it necessary to use something like
Actually I've realised the guard won't be invoked on Python 2, anyway: I later
added a "raise ImportError() from e" in an exception handler, which leads to a
syntax error in Python 2 before the guard even gets executed.
So, I'll remove the guard (as it does nothing useful anyway) and think a bit
more about not failing on Python 2. Perhaps - not use the "from" syntax in the
exception handler, and do a no-op in register_hook if on Python 2.
> Also: have you though about providing a context manager which does
> register_hook() in __enter__() and unregister_hook() in __exit__()?
Of course, things like this can be added without too much trouble.
Thanks for the feedback.
Regards,
Vinay Sajip
More information about the Python-Dev
mailing list