global
statement detected PYL-W0603 68 self.assertEqual(calls, 0)
69
70 def test_insert_batches(self):
71 global calls 72 calls = 0
73 lore.io.main.insert(self.table.name, self.dataframe, batch_size=100)
74 self.assertEqual(calls, 0)
19calls = 0
20@event.listens_for(Engine, "after_cursor_execute")
21def count_sql_calls(conn, cursor, statement, parameters, context, executemany):
22 global calls 23 calls += 1
24
25
62 self.assertEqual(self.dataframe['last_name'].tolist(), selected['last_name'].tolist())
63
64 def test_insert_bulk(self):
65 global calls 66 calls = 0
67 lore.io.main.insert(self.table.name, self.dataframe)
68 self.assertEqual(calls, 0)
169
170@contextmanager
171def timer(message='elapsed time:', level=logging.INFO, logger=None, librato=True):
172 global _librato, _nested_timers, _previous_timer_level, _ascii_pipes, _timer_logger173
174 if logger is None:
175 logger = _timer_logger
365
366
367 def librato_record(name, value):
368 global _librato, _librato_lock, _librato_aggregator, _librato_timer, _librato_start369
370 if _librato is None:
371 return
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.