__missing__ for the top-level Python script

Chris Angelico rosuav at gmail.com
Wed Nov 12 18:52:20 CET 2014


On Thu, Nov 13, 2014 at 2:16 AM, Dave Angel <davea at davea.name> wrote:
> I gave it a short whirl, just trying to make __missing__ work.
>
> The type of globals () is a dict. I was able to add a
>  __missing__:myfunct to the instance but in order to work, the
>  __missing__ must be added as a class attribute,  a method. And
>  dict, being implemented in C, doesn't let you add class
>  attributes. Presumably the C code does the equivalent of
>  slots.

Yeah, I tried doing some of that kind of work and failed. Was hoping
someone with more knowledge of internals could pull it off.

> So the next thing to try would be to try to force the module
>  dictionary to be a userdict without slots. Then we could add the
>  necessary method. But that would be changing the python source. I
>  wasn't sure that was within the challenge constraints.

Haha! Well, unless we can convince people that this would really be a
good feature (which, somehow, I doubt...), not really. Though if it
can be enabled with a tiny patch to Python and then most of the magic
worked in PYTHONSTARTUP, that might do... but I suspect it'd need to
be fairly specifically coded.

ChrisA



More information about the Python-list mailing list