private void AddProperty(FunctionDefinition fd, PythonType declaringType, bool isAbstract)
 {
     if (!(_eval.LookupNameInScopes(fd.Name, LookupOptions.Local) is PythonPropertyType p))
     {
         p = new PythonPropertyType(fd, _eval.GetLocationOfName(fd), declaringType, isAbstract);
         // The variable is transient (non-user declared) hence it does not have location.
         // Property type is tracking locations for references and renaming.
         _eval.DeclareVariable(fd.Name, p, VariableSource.Declaration);
         _typeMap[fd] = p;
         declaringType?.AddMember(p.Name, p, overwrite: true);
     }
     AddOverload(fd, p, o => p.AddOverload(o));
 }
 private void AddFunction(FunctionDefinition fd, PythonType declaringType)
 {
     if (!(_eval.LookupNameInScopes(fd.Name, LookupOptions.Local) is PythonFunctionType f))
     {
         f = new PythonFunctionType(fd, declaringType, _eval.GetLocationOfName(fd));
         // The variable is transient (non-user declared) hence it does not have location.
         // Function type is tracking locations for references and renaming.
         _eval.DeclareVariable(fd.Name, f, VariableSource.Declaration);
         _typeMap[fd] = f;
         declaringType?.AddMember(f.Name, f, overwrite: true);
     }
     AddOverload(fd, f, o => f.AddOverload(o));
 }
        private void AddFunction(FunctionDefinition fd, PythonType declaringType)
        {
            if (!(_eval.LookupNameInScopes(fd.Name, LookupOptions.Local) is PythonFunctionType f))
            {
                f = new PythonFunctionType(fd, declaringType, _eval.GetLocationOfName(fd));
                // The variable is transient (non-user declared) hence it does not have location.
                // Function type is tracking locations for references and renaming.

                // if there are multiple functions with same name exist, only the very first one will be
                // maintained in the scope. we should improve this if possible.
                // https://github.com/microsoft/python-language-server/issues/1693
                _eval.DeclareVariable(fd.Name, f, VariableSource.Declaration);
                _typeMap[fd] = f;
                declaringType?.AddMember(f.Name, f, overwrite: true);
            }
            AddOverload(fd, f, o => f.AddOverload(o));
        }
        private PythonClassType CreateClass(ClassDefinition cd)
        {
            PythonType declaringType = null;

            if (!(cd.Parent is PythonAst))
            {
                Debug.Assert(_typeMap.ContainsKey(cd.Parent));
                _typeMap.TryGetValue(cd.Parent, out declaringType);
            }
            var cls = new PythonClassType(cd, declaringType, _eval.GetLocationOfName(cd),
                                          _eval.SuppressBuiltinLookup ? BuiltinTypeId.Unknown : BuiltinTypeId.Type);

            _typeMap[cd] = cls;

            declaringType?.AddMember(cls.Name, cls, overwrite: true);
            return(cls);
        }
        private PythonClassType CreateClass(ClassDefinition cd)
        {
            PythonType declaringType = null;

            if (!(cd.Parent is PythonAst))
            {
                if (!_typeMap.TryGetValue(cd.Parent, out declaringType))
                {
                    // we can get into this situation if parent is defined twice and we preserve
                    // only one of them.
                    // for example, code has function definition with exact same signature
                    // and class is defined under one of that function
                    return(null);
                }
            }
            var cls = new PythonClassType(cd, declaringType, _eval.GetLocationOfName(cd),
                                          _eval.SuppressBuiltinLookup ? BuiltinTypeId.Unknown : BuiltinTypeId.Type);

            _typeMap[cd] = cls;

            declaringType?.AddMember(cls.Name, cls, overwrite: true);
            return(cls);
        }