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…
No comments yet. Log in to reply on the Fediverse. Comments will appear here.