def build_zero_subsection_grade(class_): def _vertical_problem_scores(self): """ Overrides the problem_scores member variable in order to return empty scores for all scorable problems in the course. """ from lms.djangoapps.grades.scores import possibly_scored #placed here to avoid circular import locations = OrderedDict() # dict of problem locations to ProblemScore for block_key in self.course_data.structure.post_order_traversal( filter_func=possibly_scored, start_node=self.location, ): vertical_score = get_vertical_score( block_key, course_structure=self.course_data.structure, submissions_scores={}, csm_scores={}, persisted_block=None, ) if vertical_score: locations[block_key] = vertical_score return locations def problem_scores(self): if feature_enabled(self.location.course_key): return self._vertical_problem_scores else: return self._old_problem_scores class_._old_problem_scores = class_.problem_scores class_._vertical_problem_scores = lazy(_vertical_problem_scores) class_.problem_scores = property(problem_scores) return class_
def _futuresByBranchAndRemote(self): if not self._remotesByBranchName: return defaultdict(dict) with warnings.catch_warnings(): warnings.filterwarnings('ignore', message='.*InsecurePlatformWarning.*') try: token = self._githubToken except ShError: return defaultdict(dict) remoteSlugs = self._remoteSlugs scheduler = Scheduler(10) futures = defaultdict(dict) for branch, remotes in self._remotesByBranchName.iteritems(): for remote in remotes: slug = remoteSlugs[remote] futures[branch][remote] = lazy(Poller( scheduler, self._getRemoteStatus, token, slug, branch)) return futures
def _futuresByServer(self): if not self._serversByRemote: return {} servers = frozenset(self._serversByRemote.values()) authByServer = self._getAuth(servers) branchesByCommit = defaultdict(set) commitsByServer = defaultdict(set) for remoteBranch in Branch.REMOTES: remote, branchName = remoteBranch.name.split('/', 1) if remote in self._serversByRemote: server = self._serversByRemote[remote] commit = remoteBranch.latestCommit.hash commitsByServer[server].add(commit) branchesByCommit[commit].add(branchName) _oldPollers = self._pollers try: with Scheduler() as scheduler: return { server : lazy(Poller(scheduler, self._getServerStatsByBranch, server, commitsByServer, branchesByCommit, authByServer[server])) for server in servers } finally: pass
try: import simplejson as json except ImportError: import json import lazy Lazy = lazy.lazy(dict, list, unicode, int, long, float, bool) def load(*s, **d): return Lazy(lambda: json.load(*s, **d))
def lazy_git_property(watching): return lambda func: lazy(LazyGitProperty(func, watching))
def lazy_git_function(watching): return lazy(listener=GitListener(include_globs=watching))
def test_lazy_lambda(): func = lazy(lambda: random()) assert func() == func()