[Python-Dev] IronPython specific code in inspect module

David Stanek dstanek at dstanek.com
Wed May 20 13:54:56 CEST 2009


On Wed, May 20, 2009 at 7:13 AM, Doug Hellmann <doug.hellmann at gmail.com> wrote:
>
> On May 19, 2009, at 10:21 PM, David Stanek wrote:
>
>>
>> It seems that using a technique similar to dependency injection could
>> provide some value. DI allows implementations conforming to some
>> interface to be injected into a running application without the messy
>> construction logic. The simple construction-by-hand pattern is to
>> create the dependencies and pass them into the dependent objects.
>> Frameworks build on top of this to allow the dependencies to be wired
>> together without having any construction logic in code, like switch
>> statements, to do the wiring.
>>
>> I think a similar pattern could be used in the standard library. When
>> the interpreter goes through its normal bootstrapping process in can
>> just execute a module provided by the vendor that specifies the
>> platform specific implementations. Some defaults can be provided since
>> Python already has a bunch of platform specific implementations.
>>
>> An over simplified design to make this happen may look like:
>> 1. Create a simple configuration that allows a mapping of interfaces
>> to implementations. This is where the vendor would say when using
>> inspect you really should be using cli.inspect.
>
> That sounds like a plugin and the "strategy" pattern.  Tarek is doing some
> work on providing a standard plugin mechanism as part of the work he's doing
> on distutils, isn't he?
>

Basically yes. What I proposed is more like a service locator with a
pinch of DI. Where can I learn more about what Tarek is working on? Is
there a branch somewhere?

>> 2. Add executing this new configuration to the bootstrapping process.
>
> Maybe I misunderstand, but wouldn't it make more sense to initialize the
> platform-specific parts of a module when it is imported rather than bring in
> everything at startup?
>

By executing I mean figure out the mappings and necessarily create
them. This enables errors to happen early if the dependencies are not
met. This is really useful if the technique is used for more than just
the platform specific code.

> Are we only worried about interpreter-implementation-level dependencies, or
> should there be a way for all platform-specific features to be treated in
> the same way?   There are quite a few checks for Windows that could be moved
> into the platform-specific modules if there was an easy/standard way to do
> it.
>

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek


More information about the Python-Dev mailing list