0

I have defined my variable as follows;

timestamp_set = set([])

def doUpdate():

    if len(timestamp_set) == 0:
        tset = get3daysoffset()
        timestamp_set = tset <---If this line removed no error warnings

In the above code block, it says timestamp_set variable in the if condition could not be resolved;

Unresolved reference 'timestamp_set' less... (⌘F1) 
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items

If I remove timestamp_set = tset line, pycharm didn't show any error warning. What is wrong here?

Ratha
  • 8,920
  • 16
  • 71
  • 141
  • try `nonlocal timestamp_set` just above the line in question. Also: why are you doing this? – Adam Smith Jul 30 '19 at 00:07
  • @AdamSmith There are other logic in between, I extracted few lines out of that..Where should I use nonlocal? Could you please provide example? – Ratha Jul 30 '19 at 00:08
  • @Ratha https://stackoverflow.com/questions/1261875/python-nonlocal-statement – AcaNg Jul 30 '19 at 00:13
  • @Ratha try adding `timestamp_set` as a parameter of `doUpdate()`. this problem happens when you are trying to assign/modify a global variable while referencing it (using in `if` condition) inside a function. see [this](https://stackoverflow.com/questions/55314981/getting-error-local-variable-referenced-before-assignment-how-to-fix) – AcaNg Jul 30 '19 at 00:29
  • 1
    I wouldn't put much stock into what that error message is saying regarding dynamic dispatch and duck typing, this seems like a simple case of this function having a common error: https://stackoverflow.com/questions/41369408/how-to-change-a-variable-after-it-is-already-defined – juanpa.arrivillaga Jul 30 '19 at 00:37

0 Answers0