global
variable is undefined PYL-W0601 51 global USER_AFK
52 global afk_time
53 global last_afk_message
54 global reason 55 USER_AFK = {}
56 afk_time = datetime.datetime.now()
57 last_afk_message = {}
A variable has been defined global in a nested scope which wasn't defined in the global namespace earlier. In this case, python will create the variable in the global namespace. This is confusing and can lead to runtime bugs.
Here's an example:
In [1]: def example():
...: global NOT_VAR
...: NOT_VAR = "Setting value inside `example` function."
...:
In [2]: # Accessing NOT_VAR will cause a `NameError` until `example` is called
In [3]: NOT_VAR
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-fc2d63c1ce6d> in <module>
----> 1 NOT_VAR
NameError: name 'NOT_VAR' is not defined
In [4]: # After calling example, the variable is created in the global namespace.
In [5]: example()
In [6]: NOT_VAR
Out[6]: 'Setting value inside `example` function.'