@@ -6628,38 +6628,60 @@ def test_inference_of_items_on_module_dict() -> None:
6628
6628
builder .file_build (str (DATA_DIR / "module_dict_items_call" / "test.py" ), "models" )
6629
6629
6630
6630
6631
- class ImportedModuleTests (resources .AstroidCacheSetupMixin ):
6632
- def test_imported_module_var_inferable (self ) -> None :
6633
- """
6634
- Module variables can be imported and inferred successfully as part of binary operators.
6635
- """
6636
- mod1 = parse ("from top.mod import v as z\n w = [1] + z" , module_name = "top" )
6637
- parse ("v = [2]" , module_name = "top.mod" )
6638
- w_val = mod1 .body [- 1 ].value
6639
- i_w_val = next (w_val .infer ())
6640
- assert i_w_val != util .Uninferable
6641
- assert i_w_val .as_string () == "[1, 2]"
6642
-
6643
- def test_imported_module_var_inferable2 (self ) -> None :
6644
- """Version list of strings."""
6645
- mod1 = parse ("from top.mod import v as z\n w = ['1'] + z" , module_name = "top" )
6646
- parse ("v = ['2']" , module_name = "top.mod" )
6647
- w_val = mod1 .body [- 1 ].value
6648
- i_w_val = next (w_val .infer ())
6649
- assert i_w_val != util .Uninferable
6650
- assert i_w_val .as_string () == "['1', '2']"
6651
-
6652
- def test_imported_module_var_inferable3 (self ) -> None :
6653
- """Version list of strings with a __dunder__ name."""
6654
- mod1 = parse (
6655
- "from top.mod import __dunder_var__ as v\n __dunder_var__ = ['w'] + v" ,
6656
- module_name = "top" ,
6657
- )
6658
- parse ("__dunder_var__ = ['v']" , module_name = "top.mod" )
6659
- w_val = mod1 .body [- 1 ].value
6660
- i_w_val = next (w_val .infer ())
6661
- assert i_w_val != util .Uninferable
6662
- assert i_w_val .as_string () == "['w', 'v']"
6631
+ def test_imported_module_var_inferable () -> None :
6632
+ """
6633
+ Module variables can be imported and inferred successfully as part of binary operators.
6634
+ """
6635
+ mod1 = parse (
6636
+ textwrap .dedent (
6637
+ """
6638
+ from top1.mod import v as z
6639
+ w = [1] + z
6640
+ """
6641
+ ),
6642
+ module_name = "top1" ,
6643
+ )
6644
+ parse ("v = [2]" , module_name = "top1.mod" )
6645
+ w_val = mod1 .body [- 1 ].value
6646
+ i_w_val = next (w_val .infer ())
6647
+ assert i_w_val is not util .Uninferable
6648
+ assert i_w_val .as_string () == "[1, 2]"
6649
+
6650
+
6651
+ def test_imported_module_var_inferable2 () -> None :
6652
+ """Version list of strings."""
6653
+ mod2 = parse (
6654
+ textwrap .dedent (
6655
+ """
6656
+ from top2.mod import v as z
6657
+ w = ['1'] + z
6658
+ """
6659
+ ),
6660
+ module_name = "top2" ,
6661
+ )
6662
+ parse ("v = ['2']" , module_name = "top2.mod" )
6663
+ w_val = mod2 .body [- 1 ].value
6664
+ i_w_val = next (w_val .infer ())
6665
+ assert i_w_val is not util .Uninferable
6666
+ assert i_w_val .as_string () == "['1', '2']"
6667
+
6668
+
6669
+ def test_imported_module_var_inferable3 () -> None :
6670
+ """Version list of strings with a __dunder__ name."""
6671
+ mod3 = parse (
6672
+ textwrap .dedent (
6673
+ """
6674
+ from top3.mod import __dunder_var__ as v
6675
+ __dunder_var__ = ['w'] + v
6676
+ """
6677
+ ),
6678
+ module_name = "top" ,
6679
+ )
6680
+ parse ("__dunder_var__ = ['v']" , module_name = "top3.mod" )
6681
+ w_val = mod3 .body [- 1 ].value
6682
+ i_w_val = next (w_val .infer ())
6683
+ assert i_w_val is not util .Uninferable
6684
+ assert i_w_val .as_string () == "['w', 'v']"
6663
6685
6664
6686
6665
6687
def test_recursion_on_inference_tip () -> None :
0 commit comments