Beispiel #1
0
    def testGetNames(self):
        source = dedent("""\
            from something import Class

            a = Class()
        """)

        expectedNames = {'Class': 'something.Class', 'a': 'Class()'}
        self.assertEquals(getNames(source, 3), expectedNames)
Beispiel #2
0
    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']))
Beispiel #3
0
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
Beispiel #4
0
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