Strange syntax error with theano

I am trying to use theano in my code right now in python 3.4. However, there are many functions with the following strange syntax

def c_code(self, node, name, (var1, var2), (var3,), sub):
...

      

i.e. they have parentheses in the function definition.

Python generates a syntax error for them

File "... / Theano-0.7.0 / theano / scalar / basic.py", line 1011
def c_code (self, node, name, (var1, var2), (var3,), sub):
                                ^ SyntaxError: invalid syntax

Now when I remove those extra brackets everything works fine, but I'm new to python and noticed that there were a lot of changes in python 3, so those brackets might need to be replaced with something else rather than removed.

Can anyone explain to me (s) what does it mean to have parentheses inside a function definition? and (b) if and how can they be made to work with python 3?

+3


source to share


1 answer


Argument unpacking in Tuple was removed in Python 3.0 via PEP3113 :

Parameter unpacking Tuple is the use of a tuple as a parameter in so that it automatically has the sequence argument unpacked. Example:

def fxn(a, (b, c), d):
    pass

      

Usage (b, c)

in the signature requires that the second argument of the function be a sequence of length two (for example [42, -13]

). When such a sequence is passed, it is unpacked and has its values ​​assigned to the parameters, as if the statement b, c = [42, -13]

were executed in the parameter.

Unfortunately, this feature of the function signature of Python's rich function capabilities, while handy in some situations, causes more problems than they are worth. Thus, this PEP suggests removing them from the language in Python 3.0.

So if you take this function signature

def fun(foo, (a, b, c), bar):
    pass

      

then it is equivalent

def fun(foo, arg, bar):
    a, b, c = arg
    pass

      



so that you achieve the same behavior with Python 3.x.

However, since this is not your own codebase, I don't see an easy way to fix this problem (other than fixing the monkeys), and there might also be more Python 3 incompatibilities that aren't as easy to spot as SyntaxError

s.


Interestingly, issue # 783 related to @tobias_k has been closed and from it it seems that support for Python 3 has been resolved and ended.In addition, Theano makes a claim that Python 3 supports according to its Trove classifiers .

However, the version you are using (0.7.0) is the most recent version, and the function signature you see is actually still found in the current onemaster

. So this is a bug, you should probably post the issue on the Theano GitHub questionnaire .

+5


source







All Articles