22
22
using Microsoft . Python . Core ;
23
23
using Microsoft . Python . Core . IO ;
24
24
using Microsoft . Python . Parsing ;
25
+ using Microsoft . Python . Parsing . Ast ;
25
26
26
27
namespace Microsoft . Python . Analysis . Modules {
27
28
/// <summary>
@@ -43,7 +44,7 @@ public BuiltinsPythonModule(string moduleName, string filePath, IServiceContaine
43
44
public override IEnumerable < string > GetMemberNames ( ) => base . GetMemberNames ( ) . Except ( _hiddenNames ) . ToArray ( ) ;
44
45
45
46
protected override string [ ] GetScrapeArguments ( IPythonInterpreter interpreter )
46
- => ! InstallPath . TryGetFile ( "scrape_module.py" , out var sb ) ? null : new [ ] { "-W" , "ignore" , "-B" , "-E" , sb } ;
47
+ => ! InstallPath . TryGetFile ( "scrape_module.py" , out var sb ) ? null : new [ ] { "-W" , "ignore" , "-B" , "-E" , sb } ;
47
48
48
49
protected override void OnAnalysisComplete ( ) {
49
50
SpecializeTypes ( ) ;
@@ -158,7 +159,9 @@ private void SpecializeFunctions() {
158
159
Analysis . SpecializeFunction ( "max" , BuiltinsSpecializations . Identity ) ;
159
160
Analysis . SpecializeFunction ( "min" , BuiltinsSpecializations . Identity ) ;
160
161
Analysis . SpecializeFunction ( "next" , BuiltinsSpecializations . Next ) ;
161
- Analysis . SpecializeFunction ( "open" , BuiltinsSpecializations . Open , new [ ] { "io" } ) ;
162
+
163
+ Analysis . SpecializeFunction ( "open" , BuiltinsSpecializations . Open , OpenConstructor ( ) , new [ ] { "io" } ) ;
164
+
162
165
Analysis . SpecializeFunction ( "ord" , Interpreter . GetBuiltinType ( BuiltinTypeId . Int ) ) ;
163
166
Analysis . SpecializeFunction ( "pow" , BuiltinsSpecializations . Identity ) ;
164
167
Analysis . SpecializeFunction ( "range" , BuiltinsSpecializations . Range ) ;
@@ -170,5 +173,26 @@ private void SpecializeFunctions() {
170
173
//SpecializeFunction(_builtinName, "sorted", ReturnsListOfInputIterable);
171
174
//SpecializeFunction(_builtinName, "super", SpecialSuper);
172
175
}
176
+
177
+ private IReadOnlyList < ParameterInfo > OpenConstructor ( ) {
178
+ if ( Interpreter . LanguageVersion . Is2x ( ) ) {
179
+ return new [ ] {
180
+ new ParameterInfo ( "name" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) , ParameterKind . Normal , null ) ,
181
+ new ParameterInfo ( "mode" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) , ParameterKind . Normal , new PythonConstant ( "r" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) ) ) ,
182
+ new ParameterInfo ( "buffering" , Interpreter . GetBuiltinType ( BuiltinTypeId . Int ) , ParameterKind . Normal , new PythonConstant ( - 1 , Interpreter . GetBuiltinType ( BuiltinTypeId . Int ) ) ) ,
183
+ } ;
184
+ } else {
185
+ return new [ ] {
186
+ new ParameterInfo ( "file" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) , ParameterKind . Normal , null ) ,
187
+ new ParameterInfo ( "mode" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) , ParameterKind . Normal , new PythonConstant ( "r" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) ) ) ,
188
+ new ParameterInfo ( "buffering" , Interpreter . GetBuiltinType ( BuiltinTypeId . Int ) , ParameterKind . Normal , new PythonConstant ( - 1 , Interpreter . GetBuiltinType ( BuiltinTypeId . Int ) ) ) ,
189
+ new ParameterInfo ( "encoding" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) , ParameterKind . Normal , new PythonConstant ( null , Interpreter . GetBuiltinType ( BuiltinTypeId . NoneType ) ) ) ,
190
+ new ParameterInfo ( "errors" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) , ParameterKind . Normal , new PythonConstant ( null , Interpreter . GetBuiltinType ( BuiltinTypeId . NoneType ) ) ) ,
191
+ new ParameterInfo ( "newline" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) , ParameterKind . Normal , new PythonConstant ( null , Interpreter . GetBuiltinType ( BuiltinTypeId . NoneType ) ) ) ,
192
+ new ParameterInfo ( "closefd" , Interpreter . GetBuiltinType ( BuiltinTypeId . Bool ) , ParameterKind . Normal , new PythonConstant ( true , Interpreter . GetBuiltinType ( BuiltinTypeId . Bool ) ) ) ,
193
+ new ParameterInfo ( "opener" , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) , ParameterKind . Normal , new PythonConstant ( null , Interpreter . GetBuiltinType ( BuiltinTypeId . Str ) ) )
194
+ } ;
195
+ }
196
+ }
173
197
}
174
198
}
0 commit comments