@@ -111,6 +111,27 @@ def test_from_import_missing_attr_path_is_canonical(self):
111111 self .assertIn (cm .exception .name , {'posixpath' , 'ntpath' })
112112 self .assertIsNotNone (cm .exception )
113113
114+ def test_from_import_star_invalid_type (self ):
115+ import re
116+ with _ready_to_import () as (name , path ):
117+ with open (path , 'w' ) as f :
118+ f .write ("__all__ = [b'invalid_type']" )
119+ globals = {}
120+ with self .assertRaisesRegex (
121+ TypeError , f"{ re .escape (name )} \.__all__ must be str"
122+ ):
123+ exec (f"from { name } import *" , globals )
124+ self .assertNotIn (b"invalid_type" , globals )
125+ with _ready_to_import () as (name , path ):
126+ with open (path , 'w' ) as f :
127+ f .write ("globals()[b'invalid_type'] = object()" )
128+ globals = {}
129+ with self .assertRaisesRegex (
130+ TypeError , f"{ re .escape (name )} \.__dict__ must be str"
131+ ):
132+ exec (f"from { name } import *" , globals )
133+ self .assertNotIn (b"invalid_type" , globals )
134+
114135 def test_case_sensitivity (self ):
115136 # Brief digression to test that import is case-sensitive: if we got
116137 # this far, we know for sure that "random" exists.
0 commit comments