TIL #143 – Resolve a lazy import manually 0 ▲ mathspp.com feed 222 days ago · Tech · hide · Fediverse post Learn how to work around the Python machinery to resolve an explicit lazy import manually. A couple of articles ago I wrote about how you could inspect a lazy import. Apparently, you can use a similar trick to check the attributes and methods that a lazy import has: >>> lazy import json >>> dir(globals()["json"]) ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'resolve'] Apart from a large number of dunder methods and dunder attributes, you'll find the method resolve. You can run help(globals()["json"].resolve) to get the help text on that method: Help on built-in function resolve: resolve() method of builtins.lazy_import instance resolves the lazy import and returns the actual object This shows that it's the method… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town