[Pywps-dev] Subclassing processes

David Huard huard.david at ouranos.ca
Mon Apr 16 11:59:46 PDT 2018


Yes, but imagine ProcessB is a subclass of ProcessA, and ProcessA's inputs
include LiteralInput instances. Then, ProcessB's inputs refer to the same
instances as ProcessA, which seems risky. In my mind, ProcessB should
instantiate its own LiteralInput instances, but I haven't found a way yet
to do this that doesn't feel clunky and unpythonic.

To clarify:

class ProcessA:
    in1 = LiteralInput(...)

    def __init__(...):
        ...
        inputs=[self.in1,...]


class ProcessB:
    in2 = LiteralInput()

        def __init__(...):
            ...
            inputs=[self.in1, self.in2, ...]

I suppose one option is to deep copy the input instances:

inputs=[self.in1.clone(), self.in2.clone(), ...]



On Mon, Apr 16, 2018 at 1:06 PM Luí­s Moreira de Sousa <
luis.de.sousa at protonmail.ch> wrote:

> Hi again David,
>
> that is the quark, strangeness and charm of Python, class properties are
> simultaneously static and instance properties. If you are not aware of
> this, then yes, you might risk "misreferencing" properties. This usually
> happens when you invoke an instance property that has not yet been
> modified/assigned. I do not find think this to be a major problem, as long
> as you always access properties through the instances.
>
> Cheers.
>
> --
> Luís Moreira de Sousa
> Bowlespark 8
> <https://maps.google.com/?q=Bowlespark+8+6701+DN+Wageningen+The+Netherlands&entry=gmail&source=g>
> 6701 DN Wageningen
> <https://maps.google.com/?q=Bowlespark+8+6701+DN+Wageningen+The+Netherlands&entry=gmail&source=g>
> The Netherlands
> <https://maps.google.com/?q=Bowlespark+8+6701+DN+Wageningen+The+Netherlands&entry=gmail&source=g>
> Phone: +31 628 544 755
> Email: luis.de.sousa at protonmail.ch
> RingID: ring:7ca91d83f4f9dec82fec9f1144b8e5c1ef2a110c
> URL: https://ldesousa.github.io
>
> Sent with ProtonMail <https://protonmail.com> Secure Email.
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On April 16, 2018 3:40 PM, David Huard <huard.david at ouranos.ca> wrote:
>
> Hi Luis,
>
> Isn't there a risk for different Process instances to share the same Input
> instances ? It seems to me that that could lead to weird behavior.
>
> Cheers,
>
> David
>
> On Sat, Apr 14, 2018 at 2:18 PM Luí­s Moreira de Sousa <
> luis.de.sousa at protonmail.ch> wrote:
>
>> Hi David,
>>
>> I have done this in the past, pretty much as you say, by promoting the
>> inputs and outputs objects to class properties. Other elements like title,
>> abstract, etc, can be treated in the same way. This would all go into an
>> "abstract" class from which actual process inherited. Perhaps there might
>> be more elegant solutions, but to me this setting served well (I am a man
>> of simple tastes).
>>
>> All that said, it could make sense defining inputs, outputs, etc as class
>> properties in the Process class itself. Something to think about.
>>
>> Happy coding. Cheers.
>>
>> --
>> Luís Moreira de Sousa
>> Bowlespark 8
>> <https://maps.google.com/?q=Bowlespark+8+6701+DN+Wageningen+The+Netherlands&entry=gmail&source=g>
>> 6701 DN Wageningen
>> <https://maps.google.com/?q=Bowlespark+8+6701+DN+Wageningen+The+Netherlands&entry=gmail&source=g>
>> The Netherlands
>> <https://maps.google.com/?q=Bowlespark+8+6701+DN+Wageningen+The+Netherlands&entry=gmail&source=g>
>> Phone: +31 628 544 755
>> Email: luis.de.sousa at protonmail.ch
>> RingID: ring:7ca91d83f4f9dec82fec9f1144b8e5c1ef2a110c
>> URL: https://ldesousa.github.io
>>
>> Sent with ProtonMail <https://protonmail.com> Secure Email.
>>
>> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
>> On April 11, 2018 11:51 PM, David Huard <huard.david at ouranos.ca> wrote:
>>
>> Hi all,
>>
>> I often find myself in situations where it would be useful to subclass a
>> Process and avoid copy-pasting shared inputs and outputs. The way most
>> processes are written does not lend itself well to this, inputs being
>> instance objects rather than class objects. I was wondering if any of you
>> had experience with an elegant way to subclass pywps processes that is
>> readable and does not pollute the class namespace too much.
>>
>> Thanks,
>>
>> david
>>
>>
>> _______________________________________________
>> pywps-dev mailing list
>> pywps-dev at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/pywps-dev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pywps-dev/attachments/20180416/be7d05ae/attachment-0001.html>


More information about the pywps-dev mailing list