[Twisted-Python] Code question - semantic meaning of IServiceCollection(parent, parent)

Dustin J. Mitchell dustin at v.igoro.us
Mon May 26 06:57:00 MDT 2014


It's certainly not an obvious syntax, but it "casts" the first
argument into a provider of the interface, defaulting to the second
argument if this is not possible.

For example, if `parent` isn't a provider of `IServiceCollection`, but
there's an adapter registered to covert to `IServiceCollection` from
`type(parent)`, then that adapter will be called.  If there's no such
adapter, the cast will return `parent`.

Dustin

On Mon, May 26, 2014 at 8:27 AM, Jonas Brunsgaard
<jonas.brunsgaard at gmail.com> wrote:
> Hello all
>
> Will someone explain to me what happens when you call an Interface with
> arguments, and why the same argument twice?
>
>
>
> My problem is to understand the semantics of the line
>
>     parent = IServiceCollection(parent, parent)
>
>
>
> part of
>
>     def setServiceParent(self, parent):
>
>         if self.parent is not None:
>
>             self.disownServiceParent()
>         parent = IServiceCollection(parent, parent)
>
>         self.parent = parent
>         self.parent.addService(self)
>
>
>
> in twisted.application.service
>
> Thanks in advance.
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>




More information about the Twisted-Python mailing list