def _dubiousConstantUpdates(self): """Return a list of fields in component that are set to be constant but seem intended to be dynamic. Some code fields are constant, and some denoted as code by $ are constant. """ warnings = [] # treat expInfo as likely to be constant; also treat its keys as # constant because its handy to make a short-cut in code: # exec(key+'=expInfo[key]') expInfo = self.exp.settings.getInfo() keywords = self.exp.namespace.nonUserBuilder[:] keywords.extend(['expInfo'] + list(expInfo.keys())) reserved = set(keywords).difference({'random', 'rand'}) for key in self.params: field = self.params[key] if (not hasattr(field, 'val') or not isinstance(field.val, basestring)): continue # continue == no problem, no warning if not (field.allowedUpdates and isinstance(field.allowedUpdates, list) and len(field.allowedUpdates) and field.updates == 'constant'): continue # now have only non-empty, possibly-code, and 'constant' updating if field.valType == 'str': if not bool(unescapedDollarSign_re.search(field.val)): continue code = getCodeFromParamStr(field.val) elif field.valType == 'code': code = field.val else: continue # get var names in the code; no names == constant try: names = compile(code, '', 'eval').co_names except SyntaxError: continue # ignore reserved words: if not set(names).difference(reserved): continue warnings.append((field, key)) return warnings or [(None, None)]
def _dubiousConstantUpdates(self, component): """Return a list of fields in component that are set to be constant but seem intended to be dynamic. Some code fields are constant, and some denoted as code by $ are constant. """ warnings = [] # treat expInfo as likely to be constant; also treat its keys as # constant because its handy to make a short-cut in code: # exec(key+'=expInfo[key]') expInfo = self.exp.settings.getInfo() keywords = self.exp.namespace.nonUserBuilder[:] keywords.extend(['expInfo'] + list(expInfo.keys())) reserved = set(keywords).difference({'random', 'rand'}) for key in component.params: field = component.params[key] if (not hasattr(field, 'val') or not isinstance(field.val, basestring)): continue # continue == no problem, no warning if not (field.allowedUpdates and isinstance(field.allowedUpdates, list) and len(field.allowedUpdates) and field.updates == 'constant'): continue # now have only non-empty, possibly-code, and 'constant' updating if field.valType == 'str': if not bool(unescapedDollarSign_re.search(field.val)): continue code = getCodeFromParamStr(field.val) elif field.valType == 'code': code = field.val else: continue # get var names in the code; no names == constant try: names = compile(code, '', 'eval').co_names except SyntaxError: continue # ignore reserved words: if not set(names).difference(reserved): continue warnings.append((field, key)) return warnings or [(None, None)]