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

Nick Coghlan ncoghlan at gmail.com
Fri Jun 1 14:07:01 CEST 2012


On Fri, Jun 1, 2012 at 9:49 PM, Mark Shannon <mark at hotpy.org> wrote:
> What is wrong with something like the following (for CPython)?
>
> class SysImplemention:
>    "Define __repr__(), etc here "
>    ...
>
> sys.implementation = SysImplemention()
> sys.implementation.name = 'cpython'
> sys.implementation.version = (3, 3, 0, 'alpha', 4)
> sys.implementation.hexversion = 0x30300a4
> sys.implementation.cache_tag = 'cpython-33'

Because now you're double keying data in a completely unnecessary
fashion. The sys module initialisation code already has access to the
info needed to fill out sys.implementation correctly, moving that code
somewhere else purely for the sake of getting to write it in Python
instead of C would be foolish. Some things are best written in Python,
some make sense to write in the underlying implementation language.
This is one of the latter because it's all about implementation
details.

> Also, should the build/machine info be removed from sys.version
> and moved it to sys.implementation?

No, as the contents of sys.version are already defined as
implementation dependent. It remains as the easy to print version,
while sys.implementation provides a programmatic interface.

There may be other CPython-specific fields currently in sys.version
that it makes sense to also include in sys.implementation, but:
1. That's *as well as*, not *instead of*
2. It's something that can be looked at *after* the initial
implementation of the PEP has been checked in (and should only be done
with a concrete use case, such as eliminating sys.version
introspection in other parts of the stdlib or in third party code)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list