Hi, I have code similar to [1] where instead of directly assigning a dictionary global variable the dictionary method update is used. Right now this results in a W0602 global-variable-not-assigned. Is this expected behavior and if so is there a better way to write the above? The actual code giving me this message is in cloud-init [2]. [1] https://paste.ubuntu.com/24330114/ [2] https://github.com/cloud-init/cloud-init/blob/master/cloudinit/util.py#L114 --- Josh Powers Ubuntu Server Canonical Ltd
* Josh Powers
I have code similar to [1] where instead of directly assigning a dictionary global variable the dictionary method update is used. Right now this results in a W0602 global-variable-not-assigned.
Is this expected behavior and if so is there a better way to write the above?
Yes. The global statement only affects variable assignments. If you don't assign to the variable, the global statement doesn't do anything and can be removed. -- Jakub Wilk
On 06/04/17 23:30, Josh Powers wrote:
Hi,
I have code similar to [1] where instead of directly assigning a dictionary global variable the dictionary method update is used. Right now this results in a W0602 global-variable-not-assigned.
Is this expected behavior and if so is there a better way to write the above?
Yes it is expected (IMHO) and the way to avoid this warning is to remove the unnecessary ``global`` declaration. You don't assign a value to the name, so don't declare it as ``global``. Ciao, Marc 'BlackJack' Rintsch -- “Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it.” -- Alan J. Perlis
participants (3)
-
Jakub Wilk
-
Josh Powers
-
Marc 'BlackJack' Rintsch