coobas / wowp

WOWP (A WOrkfloW Framework in Python) is a modern, light-weight framework for integrated simulations in science.
http://pythonic.eu/wowp/
MIT License
2 stars 1 forks source link

FuncActor outport name guessing conflicts with type annotations #10

Closed coobas closed 6 years ago

coobas commented 6 years ago

Originally reported by: Jan Pipek (Bitbucket: janpipek, GitHub: janpipek)


A type-annotated function, using the syntax recommended in Python 3.5(?), like this:

#!python

def greeting(name: str) -> str:
    return 'Hello ' + name

FuncActor(greeting)

Cannot be converted to a FuncActor:

#!

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-2ae49fe35a1c> in <module>()
      2     return 'Hello ' + name
      3 
----> 4 FuncActor(greeting)

~/code/my/wowp/wowp/actors/base.py in __init__(self, func, args, kwargs, outports, inports, name)
     66         elif isinstance(outports, six.string_types):
     67             outports = (outports, )
---> 68         for name in outports:
     69             self.outports.append(name)
     70 

TypeError: 'type' object is not iterable

We should adapt the FuncActor to deal with this syntax or at least fail with a more meaningful message.


coobas commented 6 years ago

Original comment by Jan Pipek (Bitbucket: janpipek, GitHub: janpipek):


The convention allows to put annotation type as string, i.e. this is also valid: def greeting(name: str) -> "str": Is that a problem though?

coobas commented 6 years ago

Original comment by Jakub Urban (Bitbucket: urbanj, GitHub: urbanj):


Resolved by checking annotations and ignoring incompatible ones: e21ba7aac859

coobas commented 6 years ago

Original comment by Jakub Urban (Bitbucket: urbanj, GitHub: urbanj):


Agree, https://www.python.org/dev/peps/pep-0484/ should be possible to swallow. We should not use types as port names though and thus I'd propose to ignore the annotation in this case. A warning might perhaps be displayed if this happens.