@@ -192,14 +192,30 @@ def visit_Call(self, node: ast.Call) -> ast.Call:
192192 node .args [1 ] = ast .Constant (value = self .mapping [node .args [1 ].value ])
193193 return node
194194
195+ def _is_globals_call (self , node : ast .expr ) -> bool :
196+ """Check if node is a call to globals()."""
197+ return (
198+ isinstance (node , ast .Call )
199+ and isinstance (node .func , ast .Name )
200+ and node .func .id == "globals"
201+ and not node .args
202+ )
203+
195204 def visit_Subscript (self , node : ast .Subscript ) -> ast .Subscript :
196205 self .generic_visit (node )
197206 if (
198- isinstance (node .value , ast .Attribute )
199- and node .value .attr == "__dict__"
200- and isinstance (node .slice , ast .Constant )
207+ isinstance (node .slice , ast .Constant )
201208 and isinstance (node .slice .value , str )
202209 and node .slice .value in self .mapping
210+ and (
211+ # __dict__['name'] pattern
212+ (
213+ isinstance (node .value , ast .Attribute )
214+ and node .value .attr == "__dict__"
215+ )
216+ # globals()['name'] pattern
217+ or self ._is_globals_call (node .value )
218+ )
203219 ):
204220 node .slice = ast .Constant (value = self .mapping [node .slice .value ])
205221 return node
@@ -212,6 +228,7 @@ class NamesObfuscator:
212228 "__file__" ,
213229 "__name__" ,
214230 "__doc__" ,
231+ "__builtins__" ,
215232 "__package__" ,
216233 "__loader__" ,
217234 "__spec__" ,
0 commit comments