global
statement detected PYL-W060388
89
90def set_configuration(new_configuration):
91 global configuration92 configuration = new_configuration
93 set_settings(configuration.get_settings())
333 connection = engine.connect()
334 connection.close()
335 except Exception as e:
336 global promt_messages337 print_formatted_text('')
338 print_formatted_text(HTML('<red><b>Connection failed:</b></red>'))
339 print_formatted_text(HTML('<red>{}</red>'.format(e)))
82 html_completer = WordCompleter(list(map(lambda x: x['name'], engines)))
83
84 def promt_message(message):
85 global promt_messages 86 promt_messages += 1
87 return HTML('{}. {}\n> '.format(promt_messages, message))
88
It is recommended not to use global
statement unless it is really necessary. Global variables are dangerous because they can be simultaneously accessed from multiple sections of a program. This frequently results in bugs. This also make code difficult to read, because they force you to search through multiple functions or even modules just to understand all the different locations where the global variable is used and modified. Read more about why it should be avoided here.