@@ -6627,6 +6627,42 @@ def test_inference_of_items_on_module_dict() -> None:
6627
6627
builder .file_build (str (DATA_DIR / "module_dict_items_call" / "test.py" ), "models" )
6628
6628
6629
6629
6630
+ class ImportedModuleTests (resources .AstroidCacheSetupMixin ):
6631
+ def test_imported_module_var_inferable (self ) -> None :
6632
+ """
6633
+ Module variables can be imported and inferred successfully as part of binary operators.
6634
+ """
6635
+ mod1 = parse (("from top.mod import v as z\n " "w = [1] + z" ), module_name = "top" )
6636
+ parse ("v = [2]" , module_name = "top.mod" )
6637
+ w_val = mod1 .body [- 1 ].value
6638
+ i_w_val = next (w_val .infer ())
6639
+ assert i_w_val != util .Uninferable
6640
+ assert i_w_val .as_string () == "[1, 2]"
6641
+
6642
+ def test_imported_module_var_inferable2 (self ) -> None :
6643
+ """Version list of strings."""
6644
+ mod1 = parse (
6645
+ ("from top.mod import v as z\n " "w = ['1'] + z" ), module_name = "top"
6646
+ )
6647
+ parse ("v = ['2']" , module_name = "top.mod" )
6648
+ w_val = mod1 .body [- 1 ].value
6649
+ i_w_val = next (w_val .infer ())
6650
+ assert i_w_val != util .Uninferable
6651
+ assert i_w_val .as_string () == "['1', '2']"
6652
+
6653
+ def test_imported_module_var_inferable3 (self ) -> None :
6654
+ """Version list of strings with a __dunder__ name."""
6655
+ mod1 = parse (
6656
+ ("from top.mod import __dunder_var__ as v\n " "__dunder_var__ = ['w'] + v" ),
6657
+ module_name = "top" ,
6658
+ )
6659
+ parse ("__dunder_var__ = ['v']" , module_name = "top.mod" )
6660
+ w_val = mod1 .body [- 1 ].value
6661
+ i_w_val = next (w_val .infer ())
6662
+ assert i_w_val != util .Uninferable
6663
+ assert i_w_val .as_string () == "['w', 'v']"
6664
+
6665
+
6630
6666
def test_recursion_on_inference_tip () -> None :
6631
6667
"""Regression test for recursion in inference tip.
6632
6668
0 commit comments