def testGetNames(self): source = dedent("""\ from something import Class a = Class() """) expectedNames = {'Class': 'something.Class', 'a': 'Class()'} self.assertEquals(getNames(source, 3), expectedNames)
def testGetNames(self): source = dedent("""\ from something import Class a = Class() class D(object): pass """) expectedNames = {'Class': 'something.Class', 'a': 'Class()'} self.assertEquals(getNames(getSafeTree(source, 3)), (expectedNames, ['D']))
def inferInstance(source, lineNo, var, PYSMELLDICT): names = getNames(source, lineNo) assignment = names.get(var, None) klass = None parents = [] if assignment: possibleMatch = funcCellRE.match(assignment) if possibleMatch: klass = possibleMatch.groups(1)[0] klass = _qualify(names.get(klass, klass), PYSMELLDICT) parents = PYSMELLDICT['CLASSES'].get(klass, {'bases': []})['bases'] return klass, parents
def testGetNames(self): source = dedent("""\ from something import Class a = Class() class D(object): pass """).replace('\n', '\r\n') expectedNames = {'Class': 'something.Class', 'a': 'Class()'} self.assertEqual(getNames(getSafeTree(source, 3)), (expectedNames, ['D']))
def inferInstance(fullPath, AST, lineNo, var, PYSMELLDICT): names, klasses = getNames(AST) assignment = names.get(var, None) klass = None parents = [] if assignment: possibleMatch = funcCellRE.match(assignment) if possibleMatch: klass = possibleMatch.groups(1)[0] if klass in klasses: path, filename = os.path.split(fullPath) packages = findRootPackageList(path, filename) if packages: packagesStr = (".".join(packages)) + "." else: packagesStr = "" klass = "%s%s.%s" % (packagesStr, filename[:-3], klass) else: klass = _qualify(names.get(klass, klass), PYSMELLDICT) parents = PYSMELLDICT['CLASSES'].get(klass, {'bases': []})['bases'] return klass, parents
def inferInstance(fullPath, AST, lineNo, var, PYSMELLDICT): names, klasses = getNames(AST) assignment = names.get(var, None) klass = None parents = [] if assignment: possibleMatch = funcCellRE.match(assignment) if possibleMatch: klass = possibleMatch.groups(1)[0] if klass in klasses: path, filename = os.path.split(fullPath) packages = findRootPackageList(path, filename) if packages: packagesStr = (".".join(packages)) + "." else: packagesStr = "" klass = "%s%s.%s" % (packagesStr, filename[:-3], klass) else: klass = _qualify(names.get(klass, klass), PYSMELLDICT) parents = PYSMELLDICT['CLASSES'].get(klass, {'bases': []})['bases'] return klass, parents