@@ -6008,7 +6008,6 @@ mod tests {
6008
6008
use crate :: semantic_index:: symbol:: FileScopeId ;
6009
6009
use crate :: semantic_index:: { global_scope, semantic_index, symbol_table, use_def_map} ;
6010
6010
use crate :: types:: check_types;
6011
- use crate :: { HasType , SemanticModel } ;
6012
6011
use ruff_db:: files:: { system_path_to_file, File } ;
6013
6012
use ruff_db:: system:: DbWithTestSystem ;
6014
6013
use ruff_db:: testing:: assert_function_query_was_not_run;
@@ -6080,29 +6079,6 @@ mod tests {
6080
6079
assert_diagnostic_messages ( diagnostics, expected) ;
6081
6080
}
6082
6081
6083
- #[ test]
6084
- fn resolve_method ( ) -> anyhow:: Result < ( ) > {
6085
- let mut db = setup_db ( ) ;
6086
-
6087
- db. write_dedented (
6088
- "src/mod.py" ,
6089
- "
6090
- class C:
6091
- def f(self): pass
6092
- " ,
6093
- ) ?;
6094
-
6095
- let mod_file = system_path_to_file ( & db, "src/mod.py" ) . unwrap ( ) ;
6096
- let class_ty = global_symbol ( & db, mod_file, "C" )
6097
- . expect_type ( )
6098
- . expect_class_literal ( ) ;
6099
- let member_ty = class_ty. member ( & db, "f" ) . expect_type ( ) ;
6100
- let func = member_ty. expect_function_literal ( ) ;
6101
-
6102
- assert_eq ! ( func. name( & db) , "f" ) ;
6103
- Ok ( ( ) )
6104
- }
6105
-
6106
6082
#[ test]
6107
6083
fn not_literal_string ( ) -> anyhow:: Result < ( ) > {
6108
6084
let mut db = setup_db ( ) ;
@@ -6229,130 +6205,6 @@ mod tests {
6229
6205
Ok ( ( ) )
6230
6206
}
6231
6207
6232
- /// A name reference to a never-defined symbol in a function is implicitly a global lookup.
6233
- #[ test]
6234
- fn implicit_global_in_function ( ) -> anyhow:: Result < ( ) > {
6235
- let mut db = setup_db ( ) ;
6236
-
6237
- db. write_dedented (
6238
- "src/a.py" ,
6239
- "
6240
- x = 1
6241
- def f():
6242
- y = x
6243
- " ,
6244
- ) ?;
6245
-
6246
- let file = system_path_to_file ( & db, "src/a.py" ) . expect ( "file to exist" ) ;
6247
- let index = semantic_index ( & db, file) ;
6248
- let function_scope = index
6249
- . child_scopes ( FileScopeId :: global ( ) )
6250
- . next ( )
6251
- . unwrap ( )
6252
- . 0
6253
- . to_scope_id ( & db, file) ;
6254
-
6255
- let x_ty = symbol ( & db, function_scope, "x" ) ;
6256
- assert ! ( x_ty. is_unbound( ) ) ;
6257
-
6258
- let y_ty = symbol ( & db, function_scope, "y" ) . expect_type ( ) ;
6259
- assert_eq ! ( y_ty. display( & db) . to_string( ) , "Literal[1]" ) ;
6260
-
6261
- Ok ( ( ) )
6262
- }
6263
-
6264
- #[ test]
6265
- fn local_inference ( ) -> anyhow:: Result < ( ) > {
6266
- let mut db = setup_db ( ) ;
6267
-
6268
- db. write_file ( "/src/a.py" , "x = 10" ) ?;
6269
- let a = system_path_to_file ( & db, "/src/a.py" ) . unwrap ( ) ;
6270
-
6271
- let parsed = parsed_module ( & db, a) ;
6272
-
6273
- let statement = parsed. suite ( ) . first ( ) . unwrap ( ) . as_assign_stmt ( ) . unwrap ( ) ;
6274
- let model = SemanticModel :: new ( & db, a) ;
6275
-
6276
- let literal_ty = statement. value . inferred_type ( & model) ;
6277
-
6278
- assert_eq ! ( format!( "{}" , literal_ty. display( & db) ) , "Literal[10]" ) ;
6279
-
6280
- Ok ( ( ) )
6281
- }
6282
-
6283
- #[ test]
6284
- fn deferred_annotation_builtin ( ) -> anyhow:: Result < ( ) > {
6285
- let mut db = setup_db ( ) ;
6286
- db. write_file ( "/src/a.pyi" , "class C(object): pass" ) ?;
6287
- let file = system_path_to_file ( & db, "/src/a.pyi" ) . unwrap ( ) ;
6288
- let ty = global_symbol ( & db, file, "C" ) . expect_type ( ) ;
6289
- let base = ty
6290
- . expect_class_literal ( )
6291
- . class
6292
- . iter_mro ( & db)
6293
- . nth ( 1 )
6294
- . unwrap ( ) ;
6295
- assert_eq ! ( base. display( & db) . to_string( ) , "<class 'object'>" ) ;
6296
- Ok ( ( ) )
6297
- }
6298
-
6299
- #[ test]
6300
- fn deferred_annotation_in_stubs_always_resolve ( ) -> anyhow:: Result < ( ) > {
6301
- let mut db = setup_db ( ) ;
6302
-
6303
- // Stub files should always resolve deferred annotations
6304
- db. write_dedented (
6305
- "/src/stub.pyi" ,
6306
- "
6307
- def get_foo() -> Foo: ...
6308
- class Foo: ...
6309
- foo = get_foo()
6310
- " ,
6311
- ) ?;
6312
- assert_public_type ( & db, "/src/stub.pyi" , "foo" , "Foo" ) ;
6313
-
6314
- Ok ( ( ) )
6315
- }
6316
-
6317
- #[ test]
6318
- fn deferred_annotations_regular_source_fails ( ) -> anyhow:: Result < ( ) > {
6319
- let mut db = setup_db ( ) ;
6320
-
6321
- // In (regular) source files, annotations are *not* deferred
6322
- // Also tests imports from `__future__` that are not annotations
6323
- db. write_dedented (
6324
- "/src/source.py" ,
6325
- "
6326
- from __future__ import with_statement as annotations
6327
- def get_foo() -> Foo: ...
6328
- class Foo: ...
6329
- foo = get_foo()
6330
- " ,
6331
- ) ?;
6332
- assert_public_type ( & db, "/src/source.py" , "foo" , "Unknown" ) ;
6333
-
6334
- Ok ( ( ) )
6335
- }
6336
-
6337
- #[ test]
6338
- fn deferred_annotation_in_sources_with_future_resolves ( ) -> anyhow:: Result < ( ) > {
6339
- let mut db = setup_db ( ) ;
6340
-
6341
- // In source files with `__future__.annotations`, deferred annotations are resolved
6342
- db. write_dedented (
6343
- "/src/source_with_future.py" ,
6344
- "
6345
- from __future__ import annotations
6346
- def get_foo() -> Foo: ...
6347
- class Foo: ...
6348
- foo = get_foo()
6349
- " ,
6350
- ) ?;
6351
- assert_public_type ( & db, "/src/source_with_future.py" , "foo" , "Foo" ) ;
6352
-
6353
- Ok ( ( ) )
6354
- }
6355
-
6356
6208
#[ test]
6357
6209
fn basic_comprehension ( ) -> anyhow:: Result < ( ) > {
6358
6210
let mut db = setup_db ( ) ;
0 commit comments