Menu

Mysterious Lazy Imports

Reddit r/Python·u/__peg_parser__·16 days ago
#KKuEfj4c
#json#lazy#import#type#globals
Reading 0:00
15s threshold

Run this on Python 3.15:

>>> lazy import json >>> type(globals()['json'])  

Now try separating that into an innocent variable:

>>> lazy import json >>> x = globals()['json'] >>> type(x)  

Looks like the same code, but what?! The output changes! Can you guess why?

(Originally asked as a Stack Overflow question, now posting here as a fun fact 😄)