I'm following this: https://tezos.b9lab.com/smartpy/language guide, but it's written for the SmartPy online IDE, I'm trying to do this all in my local dev environment.

PyCharm IDE gives me an "An illegal target for a variable annotation" error when I use the sp.for_. Can anyone help me understand what am I doing wrong?

import smartpy as sp

class Summarise(sp.Contract):
    def __init__(self):

    def sum(self, params):
        sp.for_ i in sp.range(1, params+1):

1 Answer 1


Found it. The desugared version is

with sp.for_("x", params) as x:
    self.data.result += x


So the translation for this example is:

with sp.for_("i", sp.range(1, params+1)) as i:
    self.data.storage += i

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.