コード例 #1
0
        }                             // For de-serializer from JSON

        protected CallableModel(IPythonType callable, IServiceContainer services)
        {
            var functions = new List <FunctionModel>();
            var classes   = new List <ClassModel>();

            foreach (var name in callable.GetMemberNames())
            {
                var m = callable.GetMember(name);

                // Only take members from this class, skip members from bases.
                using (_processing.Push(m, out var reentered)) {
                    if (reentered)
                    {
                        continue;
                    }
                    switch (m)
                    {
                    case IPythonFunctionType ft1 when ft1.IsLambda():
                        break;

                    case IPythonFunctionType ft2:
                        functions.Add(new FunctionModel(ft2, services));
                        break;

                    case IPythonClassType cls:
                        classes.Add(new ClassModel(cls, services));
                        break;
                    }
                }
            }

            Id   = callable.Name.GetStableHash();
            Name = callable.Name;
            DeclaringModuleId = callable.DeclaringModule.GetUniqueId(services);
            QualifiedName     = callable.QualifiedName;
            Documentation     = callable.Documentation;
            Classes           = classes.ToArray();
            Functions         = functions.ToArray();
            IndexSpan         = callable.Location.IndexSpan.ToModel();

            Attributes = FunctionAttributes.Normal;
            if (callable.IsAbstract)
            {
                Attributes |= FunctionAttributes.Abstract;
            }
            if (callable is IPythonFunctionType ft)
            {
                if (ft.IsClassMethod)
                {
                    Attributes |= FunctionAttributes.ClassMethod;
                }
                if (ft.IsStatic)
                {
                    Attributes |= FunctionAttributes.Static;
                }
            }
        }
コード例 #2
0
        private static IEnumerable <IPythonFunction> GetTestCaseMembers(IPythonType cls, IModuleContext context)
        {
            var methodFunctions = cls.GetMemberNames(context).Select(n => cls.GetMember(context, n))
                                  .OfType <IPythonFunction>()
                                  .ToArray();

            var tests   = methodFunctions.Where(v => v.Name.StartsWithOrdinal("test"));
            var runTest = methodFunctions.Where(v => v.Name.Equals("runTest"));

            if (tests.Any())
            {
                return(tests);
            }
            else
            {
                return(runTest);
            }
        }
コード例 #3
0
ファイル: BaseAnalysisTest.cs プロジェクト: rsumner33/PTVS
        public BaseAnalysisTest(IPythonInterpreter interpreter)
        {
            Interpreter   = interpreter;
            PyObjectType  = Interpreter.GetBuiltinType(BuiltinTypeId.Object);
            IntType       = Interpreter.GetBuiltinType(BuiltinTypeId.Int);
            ComplexType   = Interpreter.GetBuiltinType(BuiltinTypeId.Complex);
            StringType    = Interpreter.GetBuiltinType(BuiltinTypeId.Str);
            FloatType     = Interpreter.GetBuiltinType(BuiltinTypeId.Float);
            TypeType      = Interpreter.GetBuiltinType(BuiltinTypeId.Type);
            ListType      = Interpreter.GetBuiltinType(BuiltinTypeId.List);
            TupleType     = Interpreter.GetBuiltinType(BuiltinTypeId.Tuple);
            BoolType      = Interpreter.GetBuiltinType(BuiltinTypeId.Bool);
            FunctionType  = Interpreter.GetBuiltinType(BuiltinTypeId.Function);
            GeneratorType = Interpreter.GetBuiltinType(BuiltinTypeId.Generator);

            _objectMembers   = PyObjectType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray();
            _strMembers      = StringType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray();
            _listMembers     = ListType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray();
            _intMembers      = IntType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray();
            _functionMembers = FunctionType.GetMemberNames(IronPythonModuleContext.DontShowClrInstance).ToArray();
        }
コード例 #4
0
ファイル: CPythonSequenceType.cs プロジェクト: xNUTs/PTVS
 public IEnumerable <string> GetMemberNames(IModuleContext moduleContext)
 {
     return(_type.GetMemberNames(moduleContext));
 }
コード例 #5
0
ファイル: AstPythonLookup.cs プロジェクト: yepeiwen/PTVS
 public IEnumerable <string> GetMemberNames(IModuleContext moduleContext) => _lookupType?.GetMemberNames(moduleContext) ?? Enumerable.Empty <string>();
コード例 #6
0
        private void MergeClass(IVariable v, IPythonClassType sourceClass, IPythonType stubType, CancellationToken cancellationToken)
        {
            // Transfer documentation first so we get class documentation
            // that comes from the class definition win over one that may
            // come from __init__ during the member merge below.
            TransferDocumentationAndLocation(sourceClass, stubType);

            // Replace the class entirely since stub members may use generic types
            // and the class definition is important. We transfer missing members
            // from the original class to the stub.
            _eval.DeclareVariable(v.Name, v.Value, v.Source);

            // First pass: go through source class members and pick those
            // that are not present in the stub class.
            foreach (var name in sourceClass.GetMemberNames().ToArray())
            {
                cancellationToken.ThrowIfCancellationRequested();

                var sourceMember = sourceClass.GetMember(name);
                if (sourceMember.IsUnknown())
                {
                    continue; // Do not add unknowns to the stub.
                }
                var sourceMemberType = sourceMember?.GetPythonType();
                if (sourceMemberType is IPythonClassMember cm && cm.DeclaringType != sourceClass)
                {
                    continue; // Only take members from this class and not from bases.
                }
                if (!IsFromThisModuleOrSubmodules(sourceMemberType))
                {
                    continue; // Member does not come from module or its submodules.
                }

                var stubMember     = stubType.GetMember(name);
                var stubMemberType = stubMember.GetPythonType();

                // Get documentation from the current type, if any, since stubs
                // typically do not contain documentation while scraped code does.
                TransferDocumentationAndLocation(sourceMemberType, stubMemberType);

                // If stub says 'Any' but we have better type, use member from the original class.
                if (stubMember != null && !(stubType.DeclaringModule is TypingModule && stubType.Name == "Any"))
                {
                    continue; // Stub already have the member, don't replace.
                }

                (stubType as PythonType)?.AddMember(name, stubMember, overwrite: true);
            }

            // Second pass: go through stub class members and if they don't have documentation
            // or location, check if source class has same member and fetch it from there.
            // The reason is that in the stub sometimes members are specified all in one
            // class while in source they may come from bases. Example: datetime.
            foreach (var name in stubType.GetMemberNames().ToArray())
            {
                cancellationToken.ThrowIfCancellationRequested();

                var stubMember = stubType.GetMember(name);
                if (stubMember.IsUnknown())
                {
                    continue;
                }
                var stubMemberType = stubMember.GetPythonType();
                if (stubMemberType is IPythonClassMember cm && cm.DeclaringType != stubType)
                {
                    continue; // Only take members from this class and not from bases.
                }

                var sourceMember = sourceClass.GetMember(name);
                if (sourceMember.IsUnknown())
                {
                    continue;
                }

                var sourceMemberType = sourceMember.GetPythonType();
                if (sourceMemberType.Location.IsValid && !stubMemberType.Location.IsValid)
                {
                    TransferDocumentationAndLocation(sourceMemberType, stubMemberType);
                }
            }
        }
コード例 #7
0
 public IEnumerable <string> GetMemberNames() => _type.GetMemberNames();
コード例 #8
0
 public IEnumerable <string> GetMemberNames(IModuleContext moduleContext) => _type.GetMemberNames(moduleContext);