(scope: PythonScope)
| 123 | } |
| 124 | |
| 125 | export function loadPythonBuiltins(scope: PythonScope) { |
| 126 | const builtinsSpec: PythonModuleSpec = builtins |
| 127 | |
| 128 | for (const name in builtinsSpec.values) { |
| 129 | const spec = builtinsSpec.values[name] |
| 130 | if (spec.isCallable) { |
| 131 | const typeInfo: VariableTypeInfo = { |
| 132 | category: TypeCategory.Function, |
| 133 | shortDoc: spec.shortDoc, |
| 134 | arguments: [], |
| 135 | } |
| 136 | if (spec.parameters) { |
| 137 | const args = spec.parameters.map((argInfo) => { |
| 138 | const arg: FunctionArgument = { |
| 139 | name: argInfo.name, |
| 140 | type: functionArgTypeMapping[argInfo.kind], |
| 141 | } |
| 142 | if (argInfo.default) { |
| 143 | arg.defaultValue = argInfo.default |
| 144 | } |
| 145 | return arg |
| 146 | }) |
| 147 | typeInfo.arguments = args |
| 148 | } |
| 149 | scope.addBuiltIn(name, { documentation: spec.shortDoc, typeInfo: typeInfo }) |
| 150 | } else { |
| 151 | const typeInfo: VariableTypeInfo = { |
| 152 | category: TypeCategory.Value, |
| 153 | typeName: spec.typeName, |
| 154 | } |
| 155 | scope.addBuiltIn(name, { documentation: spec.shortDoc, typeInfo: typeInfo }) |
| 156 | } |
| 157 | } |
| 158 | for (const name in builtinsSpec.types) { |
| 159 | const spec = builtinsSpec.types[name] |
| 160 | |
| 161 | const attributes: Map<string, VariableTypeInfo> = new Map() |
| 162 | Object.values(spec.attributes).forEach((attr) => { |
| 163 | if (!attr.isCallable) { |
| 164 | attributes.set(attr.name, { |
| 165 | category: TypeCategory.Value, |
| 166 | typeName: attr.typeName, |
| 167 | typeIfAttr: spec.name, |
| 168 | }) |
| 169 | } else { |
| 170 | const attrInfo: FunctionSignature = { |
| 171 | category: TypeCategory.Function, |
| 172 | shortDoc: attr.shortDoc, |
| 173 | arguments: |
| 174 | attr.parameters?.map((argInfo) => { |
| 175 | const arg: FunctionArgument = { |
| 176 | name: argInfo.name, |
| 177 | type: functionArgTypeMapping[argInfo.kind], |
| 178 | } |
| 179 | if (argInfo.default) { |
| 180 | arg.defaultValue = argInfo.default |
| 181 | } |
| 182 | return arg |
no test coverage detected