[Python-Dev] a new type for sys.implementation

Barry Warsaw barry at python.org
Thu May 31 17:02:23 CEST 2012


On May 31, 2012, at 01:21 AM, Eric Snow wrote:

>The implementation for sys.implementation is going to use a new (but
>"private") type[1].  It's basically equivalent to the following:
>
>class namespace:
>    def __init__(self, **kwargs):
>        self.__dict__.update(kwargs)
>    def __repr__(self):
>        keys = (k for k in self.__dict__ if not k.startswith('_'))
>        pairs = ("{}={!r}".format(k, self.__dict__[k]) for k in sorted(keys))
>        return "{}({})".format(type(self).__name__, ", ".join(pairs))
>
>There were other options for the type, but the new type was the best
>fit and not hard to do.  Neither the type nor its API is directly
>exposed publicly, but it is still accessible through
>"type(sys.implementation)".

I did the initial review of the four patches that Eric uploaded and I agreed
with him that this was the best fit for sys.implementation.  (I need to review
his updated patch, which I'll try to get to later today.)

>This brings me to a couple of questions:
>
>1. should we make the new type un-instantiable (null out tp_new and tp_init)?

I don't think this is necessary.

>2. would it be feasible to officially add the type (or something like
>it) in 3.3 or 3.4?

I wouldn't be against it, but the implementation above (or really, the C
equivalent in Eric's patch) isn't quite appropriate to be that type.
Specifically, while I think that filtering out _names in the repr is fine for
sys.implementation, it would not be appropriate for a generalized, public
type.

OTOH, I'd have no problem just dropping that detail from sys.implementation
too.  (Note of course that even with that, you can get the full repr via
sys.implementation.__dict__.)

Cheers,
-Barry


More information about the Python-Dev mailing list