HHousen / lecture2notes

Unguarded next inside generator PTC-W0063
Bug risk
Critical
3 years ago3 years old
Call to next() should be wrapped in try-except
 212    logger.debug("Ranks calculated")
 213
 214    sentences = get_best_sentences(
 215        NLP_SENTENCES, NUM_SENTENCES_IN_SUMMARY, lambda s: next(ranks) 216    )
 217    logger.debug("Top " + str(NUM_SENTENCES_IN_SUMMARY) + " sentences found")
 218
Call to next() should be wrapped in try-except
 69
 70        # Save the original state of the model and optimizer so they can be restored if
 71        # needed
 72        self.model_device = next(self.model.parameters()).device 73        self.state_cacher = StateCacher(memory_cache, cache_dir=cache_dir)
 74        self.state_cacher.store("model", self.model.state_dict())
 75        self.state_cacher.store("optimizer", self.optimizer.state_dict())
Call to next() should be wrapped in try-except
 19class _BaseWrapper:
 20    def __init__(self, model):
 21        super(_BaseWrapper, self).__init__()
 22        self.device = next(model.parameters()).device 23        self.model = model
 24        self.handlers = []  # a set of hook function handlers
 25