[Python-Dev] a new type for sys.implementation (original) (raw)
Barry Warsaw barry at python.org
Thu May 31 17:02:23 CEST 2012
- Previous message: [Python-Dev] a new type for sys.implementation
- Next message: [Python-Dev] [RELEASED] Python 3.3.0 alpha 4
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 tpnew and tpinit)?
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
- Previous message: [Python-Dev] a new type for sys.implementation
- Next message: [Python-Dev] [RELEASED] Python 3.3.0 alpha 4
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]