[Python-ideas] PEP: Distributing a Subset of the Standard Library

Ethan Furman ethan at stoneleaf.us
Mon Nov 28 16:48:48 EST 2016


On 11/28/2016 01:26 PM, Paul Moore wrote:
> On 28 November 2016 at 21:11, Ethan Furman <ethan at stoneleaf.us> wrote:
>> One "successful" use-case that would be impacted is the fallback import
>> idiom:
>>
>> try:
>>      # this would do two full searches before getting the error
>>      import BlahBlah
>> except ImportError:
>>      import blahblah
>
> Under this proposal, the above idiom could potentially now fail. If
> there's a BlahBlah.missing.py, then that will get executed rather than
> an ImportError being raised, so the fallback wouldn't be executed.

Which is why the strong recommendation is for the .missing.py file to raise an ImportError exception, but with a useful error message, such as "Tkinter is not currently installed.  Install python-tkinter to get it."

> This could actually be a serious issue for code that currently
> protects against optional stdlib modules not being available like
> this. There's no guarantee that I can see that a .missing.py file
> would raise ImportError (even if we said that was the intended
> behaviour, there's nothing to enforce it).

Presumably the folks doing the splitting know what they are doing.  Any cPython auto-generated .missing.py files would be correct:

raise ImportError("tkinter was not compiled due to ...") .

> Could the proposal execute the .missing.py file and then raise
> ImportError? I could imagine that having problems of its own,
> though...

Yeah, I don't think that's a good idea.

--
~Ethan~


More information about the Python-ideas mailing list